﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Management;
using System.IO;
using System.Collections;
using System.Drawing;
using System.Collections.ObjectModel;
using System.Threading;
using System.Windows.Threading;
using System.ComponentModel;
using System.Security;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Net;
using System.Web.Services;
using System.Web.Services.Protocols;




namespace AzureDriverExplorer_Client
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private string Localpath = string.Empty;
        private string Azurepath = string.Empty;
        private List<string> ListCopy = new List<string>();

        private List<string> ListCopyAzure = new List<string>();
        private int CancelUpload = -1;
        private bool CancelDownload = false;
        private int DownloadFileIndex = -1;
        private WebClient webClient;
        private System.Threading.Thread threadDownload;
        private System.Threading.Thread threadUpload;
        private Const cons = new Const();
        //MSG
        private System.Resources.ResourceManager ResManager;

        private Comm comm = new Comm();
        //Azure
        private static GetListVHD.AzureDriveExplorerServiceSoapClient Azure = new GetListVHD.AzureDriveExplorerServiceSoapClient();


        public MainWindow()
        {
            // icon設定
            this.Icon = this._GetIconSource("logoicon2");
            InitializeComponent();
            initializeListFile();
            LoaderFolderAzure();


            ComboBoxItem selected = (ComboBoxItem)CBLanguage.Items[int.Parse(Const.keyLanguage())];
            selected.IsSelected = true;

            //Progress名を入れます
            threadDownload = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                while (true)
                {

                    System.Threading.Thread.Sleep(3000);
                    Download();

                }
            }));
            threadDownload.Start();


            //Progress名を入れます
            threadUpload = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                while (true)
                {

                    System.Threading.Thread.Sleep(3000);
                    Upload();


                }
            }));
            threadUpload.Start();
        }

        /// <summary>
        /// Azureドライブを取っています
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoaderFolderAzure()
        {
            //Azure
            GetListVHD.ArrayOfString ListVHD = null;

            Loading fsplash = new Loading();

            if (fsplash.ShowDialog() == false) this.Close();
            ListVHD = fsplash.ListVHD;

            if (ListVHD != null)
                foreach (string path in ListVHD)
                {
                    TreeViewItem Item = CreateTreeViewItem(string.Empty, path, "Image/TreeView/", "Private.ico");
                    Item.Expanded += new RoutedEventHandler(treeViewAzure_Expand);

                    List<string> SubFolder = getListDirectoryAzure(path);
                    if (SubFolder.Count > 0)
                    {
                        foreach (string dir in SubFolder)
                        {
                            TreeViewItem ItemChir = CreateTreeViewItem(dir, comm.LastNamePath(dir), "Image/TreeView/", "CloseFolder.ico");
                            ItemChir.Expanded += new RoutedEventHandler(treeViewAzure_Expand);

                            Item.Items.Add(ItemChir);
                        }

                    }

                    Tre_Azure.Items.Add(Item);
                }
        }

        /// <summary>
        /// AzureドライブのSubフォルダを取っています
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private List<string> getListDirectoryAzure(string path)
        {

            //Azure
            GetListVHD.ArrayOfString listDirectory;


            List<string> strlist = new List<string>();
            listDirectory = Azure.getDirectory(comm.FirstPath(path), Const.key());

            if (listDirectory != null)
                foreach (string str in listDirectory)
                    strlist.Add(str);

            return strlist;

        }



        /// <summary>
        /// ローカルドライブを取っています
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void initializeListFile()
        {
            //language(numLanguage);

            ////Directory
            //Tre_Local.ImageList = this.imageListTree;


            System.Management.ManagementObjectSearcher ms = new System.Management.ManagementObjectSearcher("SELECT * FROM win32_logicaldisk");
            foreach (ManagementObject mo in ms.Get())
            {

                string path = mo["deviceid"].ToString() + "\\";
                try
                {

                    string[] filePaths = Directory.GetDirectories(path);

                    TreeViewItem Item = CreateTreeViewItem(string.Empty, path, "Image/TreeView/", "Private.ico");

                    Item.Expanded += new RoutedEventHandler(treeViewLocal_Expand);


                    if (filePaths.Length > 0)
                    {


                        foreach (string dir in filePaths)
                        {
                            TreeViewItem ItemChir = CreateTreeViewItem(dir, comm.LastNamePath(dir), "Image/TreeView/", "CloseFolder.ico");
                            ItemChir.Expanded += new RoutedEventHandler(treeViewLocal_Expand);


                            Item.Items.Add(ItemChir);
                        }

                    }

                    Tre_Local.Items.Add(Item);

                }
                catch { }

            }

            //this.Load += new EventHandler(fMain_Load);

            //Azure Get List
            //ListContainers();
            //local
            //GetListAzure();

        }



        /// <summary>
        /// treeviweローカルを開いているとき
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewLocal_Expand(object sender, RoutedEventArgs e)
        {

            TreeViewItem TvLocal = (TreeViewItem)e.Source;

            ChangeImageSelectedItems(ref TvLocal, "Image/TreeView/", "OpenFolder.ico");

            foreach (TreeViewItem item in TvLocal.Items)
            {
                string path = (string)item.Tag;
                try
                {
                    string[] filePaths = Directory.GetDirectories(path);
                    if (filePaths.Length > 0)
                    {
                        if (item.Items.Count == 0)
                            foreach (string dir in filePaths)
                            {
                                TreeViewItem ItemChir = CreateTreeViewItem(dir, comm.LastNamePath(dir), "Image/TreeView/", "CloseFolder.ico");
                                ItemChir.Expanded += new RoutedEventHandler(treeViewLocal_Expand);
                                item.Items.Add(ItemChir);
                            }
                    }
                }
                //パースへのアクセスが拒否されました
                catch { }
            }

        }


        /// <summary>
        /// treeviweAzureを開いているとき
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewAzure_Expand(object sender, RoutedEventArgs e)
        {

            TreeViewItem TvLocal = (TreeViewItem)e.Source;

            ChangeImageSelectedItems(ref TvLocal, "Image/TreeView/", "OpenFolder.ico");

            foreach (TreeViewItem item in TvLocal.Items)
            {
                string path = (string)item.Tag;
                try
                {
                    List<string> SubFolder = getListDirectoryAzure(path);
                    if (SubFolder.Count > 0)
                    {
                        //if (item.Items.Count == 0)
                        item.Items.Clear();
                        foreach (string dir in SubFolder)
                        {
                            TreeViewItem ItemChir = CreateTreeViewItem(dir, comm.LastNamePath(dir), "Image/TreeView/", "CloseFolder.ico");
                            ItemChir.Expanded += new RoutedEventHandler(treeViewLocal_Expand);
                            item.Items.Add(ItemChir);
                        }
                    }
                }
                //パースへのアクセスが拒否されました
                catch { }
            }

        }



        /// <summary>
        /// treeviweをTextとicoを表示される
        /// </summary>
        /// <param></param>  
        private TreeViewItem CreateTreeViewItem(string FullPath, string header, string iconFolder, string iconName)
        {
            TreeViewItem child = new TreeViewItem();
            StackPanel pan = new StackPanel();
            if (iconName != null)
            {
                try
                {
                    pan.Orientation = Orientation.Horizontal;
                    Stream iconstm = this._MakeIconStream(iconName);
                    IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                    System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                    image.Height = Const.TreeIcoSize;
                    image.Source = icon.Frames[0];
                    pan.Children.Add(image);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            TextBlock text = new TextBlock();
            text.Text = " " + header;
            pan.Children.Add(text);
            child.Header = pan;
            child.Tag = FullPath;
            return child;
        }

        /// <summary>
        /// treeviweをTextとicoを変更される
        /// </summary>
        /// <param></param>  
        private void ChangeImageSelectedItems(ref TreeViewItem child, string iconFolder, string iconName)
        {

            StackPanel Oldpan = (StackPanel)child.Header;
            StackPanel pan = new StackPanel();
            TextBlock text = (TextBlock)Oldpan.Children[1];

            if (iconName != null && !child.Tag.Equals(string.Empty) && !text.Text.Equals(string.Empty))
            {
                pan.Orientation = Orientation.Horizontal;
                Stream iconstm = this._MakeIconStream(iconName);
                IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                image.Height = Const.TreeIcoSize;
                image.Source = icon.Frames[0];
                pan.Children.Add(image);
            }
            else
            {
                return;
            }
            TextBlock Temptext = new TextBlock();
            Temptext.Text = " " + text.Text.Trim();
            pan.Children.Add(Temptext);
            child.Header = pan;


        }

        private ImageSource _GetIconSource(string iconName)
        {
            Stream iconstm = this._MakeIconStream(iconName);
            IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
            return icon.Frames[0];
        }

        private Stream _MakeIconStream(string name)
        {
            Icon icon = null;
            switch (name)
            {
                case "Private.ico":
                    icon = Properties.Resources.Private;
                    break;
                case "CloseFolder.ico":
                    icon = Properties.Resources.CloseFolder;
                    break;
                case "OpenFolder.ico":
                    icon = Properties.Resources.OpenFolder;
                    break;
                case "logoicon2":
                    icon = Properties.Resources.logoicon2;
                    break;
            }

            MemoryStream stm = new MemoryStream();
            icon.Save(stm);


            return stm;
        }



        /// <summary>
        /// ローカルドライブのファイルのInfoを取っています
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private ArrayList GetLocalInformationFile(string path)
        {

            ArrayList list = new ArrayList();

            //パース保存
            this.Localpath = path;
            //Actualize path with click
            LocalGoTXT.Text = this.Localpath;

            try
            {
                string[] Files = Directory.GetFiles(path);
                foreach (string FilePath in Files)
                {
                    FileInfo fileinfo = new FileInfo(FilePath);

                    list.Add(new DataList(fileinfo.Name.ToString(), fileinfo.LastWriteTime.ToString(), fileinfo.Extension.ToString(), (long)fileinfo.Length, fileinfo.IsReadOnly.ToString()));
                }

                string[] Folder = Directory.GetDirectories(path);
                foreach (string FilePath in Folder)
                {
                    DirectoryInfo directoryinfo = new DirectoryInfo(FilePath);
                    list.Add(new DataList(directoryinfo.Name.ToString(), directoryinfo.LastWriteTime.ToString(), Const._Directory, 0, directoryinfo.Attributes.ToString()));
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            return list;
        }


        /// <summary>
        /// ListViewLocalにデータを入れます
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Tre_Local_Selected(object sender, RoutedEventArgs e)
        {

            TreeViewItem TvLocal = (TreeViewItem)e.Source;
            //Fill List
            if (!TvLocal.Tag.ToString().Equals(string.Empty))
            {
                ListViewLocal.ItemsSource = GetLocalInformationFile(TvLocal.Tag.ToString());
            }
            else
            {
                StackPanel pan = (StackPanel)TvLocal.Header;
                TextBlock text = (TextBlock)pan.Children[1];
                if (!text.Text.Equals(string.Empty))
                    ListViewLocal.ItemsSource = GetLocalInformationFile(text.Text);

            }

        }

        /// <summary>
        /// ListViewLocalにデータを入れます
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Tre_Azure_Selected(object sender, RoutedEventArgs e)
        {

            TreeViewItem TvLocal = (TreeViewItem)e.Source;
            //Fill List
            if (!TvLocal.Tag.ToString().Equals(string.Empty))
                ListViewAzure.ItemsSource = GetAzureInformationFile(TvLocal.Tag.ToString());
            else
            {
                StackPanel pan = (StackPanel)TvLocal.Header;
                TextBlock text = (TextBlock)pan.Children[1];
                if (!text.Text.Equals(string.Empty))
                    ListViewAzure.ItemsSource = GetAzureInformationFile(text.Text);

            }

        }

        /// <summary>
        /// AzureドライブのファイルのInfoを取っています
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private List<DataList> GetAzureInformationFile(string path)
        {

            //Azure
            GetListVHD.ArrayOfString listFiles;
            List<DataList> strlist = new List<DataList>();

            //パース保存
            this.Azurepath = path;
            //Actualize path with click
            AzureGoTXT.Text = this.Azurepath;

            listFiles = Azure.getFiles(comm.FirstPath(path), Const.key());

            if (listFiles != null)
                foreach (string str in listFiles)
                {

                    string[] getInfoFile = str.Split('|');

                    DataList datalist = new DataList(getInfoFile[0], getInfoFile[1], getInfoFile[2], long.Parse(getInfoFile[3].ToString()), getInfoFile[4]);
                    strlist.Add(datalist);
                }

            return strlist;
        }


        private GridViewColumnHeader _CurSortCol = null;
        private SortAdorner _CurAdorner = null;

        /// <summary>
        /// ListViewLocalのshort
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SortLocalClick(object sender, RoutedEventArgs e)
        {

            GridViewColumnHeader column = sender as GridViewColumnHeader;
            string field = column.Tag as string;

            if (_CurSortCol != null)
            {
                AdornerLayer.GetAdornerLayer(_CurSortCol).Remove(_CurAdorner);
                ListViewLocal.Items.SortDescriptions.Clear();
            }

            ListSortDirection newDir = ListSortDirection.Ascending;
            if (_CurSortCol == column && _CurAdorner.Direction == newDir)
                newDir = ListSortDirection.Descending;
            else
                newDir = ListSortDirection.Ascending;


            _CurSortCol = column;
            _CurAdorner = new SortAdorner(_CurSortCol, newDir);
            AdornerLayer.GetAdornerLayer(_CurSortCol).Add(_CurAdorner);
            ListViewLocal.Items.SortDescriptions.Add(new SortDescription(field, newDir));
        }

        /// <summary>
        /// ListViewAzureのshort
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SortAzureClick(object sender, RoutedEventArgs e)
        {

            GridViewColumnHeader column = sender as GridViewColumnHeader;
            string field = column.Tag as string;

            if (_CurSortCol != null)
            {
                AdornerLayer.GetAdornerLayer(_CurSortCol).Remove(_CurAdorner);
                ListViewAzure.Items.SortDescriptions.Clear();
            }

            ListSortDirection newDir = ListSortDirection.Ascending;
            if (_CurSortCol == column && _CurAdorner.Direction == newDir)
                newDir = ListSortDirection.Descending;
            else
                newDir = ListSortDirection.Ascending;


            _CurSortCol = column;
            _CurAdorner = new SortAdorner(_CurSortCol, newDir);
            AdornerLayer.GetAdornerLayer(_CurSortCol).Add(_CurAdorner);
            ListViewAzure.Items.SortDescriptions.Add(new SortDescription(field, newDir));
        }



        public System.Windows.Point startPoint;
        private void List_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Store the mouse position
            startPoint = e.GetPosition(null);

        }

        /// <summary>
        /// Local -> Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void List_MouseMove(object sender, MouseEventArgs e)
        {
            //Avilite Drop in Azure and Disabilite in Local
            this.ListViewLocal.AllowDrop = false;
            this.ListViewAzure.AllowDrop = true;


            // Get the current mouse position
            System.Windows.Point mousePos = e.GetPosition(null);
            Vector diff = startPoint - mousePos;


            if (e.LeftButton == MouseButtonState.Pressed &&
                Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance &&
                Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
            {

                // Get the dragged ListViewItem
                ListView listView = sender as ListView;
                ListViewItem listViewItem = FindAnchestor<ListViewItem>((DependencyObject)e.OriginalSource);
                if (listViewItem == null)
                    return;
                // Find the data behind the ListViewItem
                DataList contact = (DataList)listView.ItemContainerGenerator.ItemFromContainer(listViewItem);

                // Initialize the drag & drop operation                
                DataObject dragData = new DataObject("DataList", contact);
                DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Move);


            }
        }



        /// <summary>
        /// Drop Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DropListLocal_DragEnter(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent("DataList") ||
                sender == e.Source)
            {
                e.Effects = DragDropEffects.Copy;
            }
        }



        // Helper to search up the VisualTree
        private static T FindAnchestor<T>(DependencyObject current)
            where T : DependencyObject
        {
            do
            {
                if (current is T)
                {
                    return (T)current;
                }
                current = VisualTreeHelper.GetParent(current);
            }
            while (current != null);
            return null;
        }


        /// <summary>
        /// Drop Local->Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DropListAzure_Drop(object sender, DragEventArgs e)
        {
            if (this.Azurepath.Equals(string.Empty))
            {
                MessageBox.Show(ResManager.GetString("Error_SelectPath" + cons.Language) + " ", string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }


            foreach (DataList dataList in ListViewLocal.SelectedItems)
            {
                if (!dataList.HiddenBytes.Equals("Hidden"))
                {
                    string Inname = string.Empty;
                    string Outname = string.Empty;

                    if (!this.Localpath.Equals(string.Empty))
                        Outname = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                    if (!this.Azurepath.Equals(string.Empty))
                        Inname = this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\");// +dataList.Name;

                    //Get the Next Index
                    int countIndex = 0;
                    if (ListViewLocalProgress.Items.Count > 0)
                    {
                        Progress countItem = (Progress)ListViewLocalProgress.Items[ListViewLocalProgress.Items.Count - 1];
                        countIndex = countItem.Index + 1;

                    }


                    Progress progres = new Progress(dataList.Name, 0, Inname, Outname, countIndex);

                    bool Add = true;
                    foreach (Progress validate in ListViewLocalProgress.Items)
                    {
                        if (validate.OutPath.Equals(progres.OutPath) && validate.Valueprogress < 100)
                            Add = false;
                    }

                    if (Add)
                    {
                        Add = true;
                        foreach (DataList validate in ListViewAzure.Items)
                        {
                            if (validate.Name.Equals(dataList.Name))
                                if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), dataList.Name), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                                    Add = false;
                        }
                        if (Add)
                        {
                            ListViewLocalProgress.Items.Add(progres);

                            if (ListViewLocal.SelectedItems.Count > 0)
                            {
                                GridViewLocalProgress.Visibility = Visibility.Visible;
                            }
                        }
                    }

                }
                else if (dataList.HiddenBytes.Equals("Hidden"))
                {
                    //Get the Next Index
                    int countIndex = 0;
                    if (ListViewLocalProgress.Items.Count > 0)
                    {
                        Progress countItem = (Progress)ListViewLocalProgress.Items[ListViewLocalProgress.Items.Count - 1];
                        countIndex = countItem.Index + 1;

                    }
                    bool Add = true;
                    foreach (DataList validate in ListViewAzure.Items)
                    {
                        if (validate.Name.Equals(dataList.Name))
                            if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), dataList.Name), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                                Add = false;
                    }
                    if (Add)
                    {
                        AddFileDirectory(dataList, this.Localpath, this.Azurepath, countIndex, this.ListViewLocalProgress, ListViewAzure);

                        if (ListViewLocal.SelectedItems.Count > 0)
                        {
                            GridViewLocalProgress.Visibility = Visibility.Visible;
                        }
                    }
                }
            }



        }


        /// <summary>
        /// Get multi folder in azure -> Local
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="Outname"></param>
        /// <param name="Inname"></param>
        /// <param name="countIndex"></param>
        /// <param name="TempListViewProgress"></param>
        /// <param name="TempListViewOtherSize"></param>
        protected void AddFileDirectoryAzure(DataList dataList, string Outname, string Inname, int countIndex, ListView TempListViewProgress, ListView TempListViewOtherSize)
        {


            string TempOutname = Outname + (Outname.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;

            GetListVHD.ArrayOfString ListDirectory = Azure.GetFileTheAllDirectory(TempOutname, Const.key());

            if (ListDirectory.Count > 0)
            {
                string[] vecValidate = ListDirectory[0].Split('|');
                if (vecValidate.Length > 1)
                    if (vecValidate[0].Equals("0"))
                    {
                        MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language).Trim() + ": " + vecValidate[1], string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
            }

            foreach (string strListDirectory in ListDirectory)
            {


                TempOutname = Outname + (Outname.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                TempOutname += (TempOutname.EndsWith(@"\") ? string.Empty : @"\") + strListDirectory;
                string TempInname = Inname + (Inname.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                TempInname += (TempInname.EndsWith(@"\") ? string.Empty : @"\") + strListDirectory;

                Progress progres = new Progress(System.IO.Path.GetFileName(TempOutname), 0, TempInname, TempOutname, countIndex);

                bool Add = true;
                foreach (Progress validate in TempListViewProgress.Items)
                {
                    if (validate.OutPath.Equals(TempOutname) && validate.Valueprogress < 100)
                        Add = false;
                }

                if (Add)
                {
                    TempListViewProgress.Items.Add(progres);
                }


                //Get the Next Index            
                countIndex += 1;
            }

        }



        /// <summary>
        /// Get multi folder in local->Azure
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="Outname"></param>
        /// <param name="Inname"></param>
        /// <param name="countIndex"></param>
        /// <param name="TempListViewProgress"></param>
        /// <param name="TempListViewOtherSize"></param>
        protected void AddFileDirectory(DataList dataList, string Outname, string Inname, int countIndex, ListView TempListViewProgress, ListView TempListViewOtherSize)
        {


            string TempOutname = Outname + (Outname.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;

            List<String> ListDirectory = comm.GetFileTheAllDirectory(TempOutname);


            foreach (string strListDirectory in ListDirectory)
            {

                TempOutname = Outname + (Outname.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                TempOutname += (TempOutname.EndsWith(@"\") ? string.Empty : @"\") + strListDirectory;
                string TempInname = Inname + (Inname.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                TempInname += (TempInname.EndsWith(@"\") ? string.Empty : @"\") + System.IO.Path.GetDirectoryName(strListDirectory);

                Progress progres = new Progress(System.IO.Path.GetFileName(TempOutname), 0, TempInname, TempOutname, countIndex);

                bool Add = true;
                foreach (Progress validate in TempListViewProgress.Items)
                {
                    if (validate.OutPath.Equals(TempOutname) && validate.Valueprogress < 100)
                        Add = false;
                }

                if (Add)
                {
                    TempListViewProgress.Items.Add(progres);
                }


                //Get the Next Index            
                countIndex += 1;
            }

        }

        public System.Windows.Point startPointAzure;
        private void List_PreviewMouseLeftButtonDownAzure(object sender, MouseButtonEventArgs e)
        {
            // Store the mouse position
            startPointAzure = e.GetPosition(null);

        }

        /// <summary>
        /// Azure -> Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void List_MouseMoveAzure(object sender, MouseEventArgs e)
        {
            //Avilite Drop in Local and Disabilite in Azure
            this.ListViewLocal.AllowDrop = true;
            this.ListViewAzure.AllowDrop = false;

            // Get the current mouse position
            System.Windows.Point mousePos = e.GetPosition(null);
            Vector diff = startPointAzure - mousePos;


            if (e.LeftButton == MouseButtonState.Pressed &&
                Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance &&
                Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
            {

                // Get the dragged ListViewItem
                ListView listView = sender as ListView;
                ListViewItem listViewItem = FindAnchestorAzure<ListViewItem>((DependencyObject)e.OriginalSource);
                if (listViewItem == null)
                    return;
                // Find the data behind the ListViewItem
                DataList contact = (DataList)listView.ItemContainerGenerator.ItemFromContainer(listViewItem);

                // Initialize the drag & drop operation                
                DataObject dragData = new DataObject("DataList", contact);
                DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Move);


            }
        }

        // Helper to search up the VisualTree
        private static T FindAnchestorAzure<T>(DependencyObject current)
            where T : DependencyObject
        {
            do
            {
                if (current is T)
                {
                    return (T)current;
                }
                current = VisualTreeHelper.GetParent(current);
            }
            while (current != null);
            return null;
        }

        /// <summary>
        /// Add items for download with menu Azure -> Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemAddDownload_Click(object sender, RoutedEventArgs e)
        {
            //MenuItem menu = sender as MenuItem;
            //DataList dataListClick = menu.DataContext as DataList;
            //bool ExistinList = false;

            if (this.Azurepath.Equals(string.Empty))
            {
                MessageBox.Show(ResManager.GetString("Error_SelectPath" + cons.Language) + " ", string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //Progress名を入れます

            foreach (DataList dataList in ListViewAzure.SelectedItems)
            {
                if (!dataList.HiddenBytes.Equals("Hidden"))
                {
                    string Inname = string.Empty;
                    string Outname = string.Empty;

                    if (!this.Localpath.Equals(string.Empty))
                        Inname = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                    if (!this.Azurepath.Equals(string.Empty))
                        Outname = this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;

                    //Get the Next Index
                    int countIndex = 0;
                    if (ListViewAzureProgress.Items.Count > 0)
                    {
                        Progress countItem = (Progress)ListViewAzureProgress.Items[ListViewAzureProgress.Items.Count - 1];
                        countIndex = countItem.Index + 1;

                    }

                    Progress progres = new Progress(dataList.Name, 0, Inname, Outname, countIndex);

                    bool Add = true;
                    foreach (Progress validate in ListViewAzureProgress.Items)
                    {
                        if (validate.OutPath.Equals(progres.OutPath) && validate.Valueprogress < 100)
                            Add = false;
                    }

                    if (Add)
                    {
                        Add = true;
                        foreach (DataList validate in ListViewLocal.Items)
                        {
                            if (validate.Name.Equals(dataList.Name))
                                if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), dataList.Name), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                                    Add = false;
                        }
                        if (Add)
                        {
                            ListViewAzureProgress.Items.Add(progres);

                            if (ListViewAzure.SelectedItems.Count > 0)
                            {
                                GridViewAzureProgress.Visibility = Visibility.Visible;
                            }
                        }

                    }
                }
                else if (dataList.HiddenBytes.Equals("Hidden"))
                {
                    //Get the Next Index
                    int countIndex = 0;
                    if (ListViewAzureProgress.Items.Count > 0)
                    {
                        Progress countItem = (Progress)ListViewAzureProgress.Items[ListViewAzureProgress.Items.Count - 1];
                        countIndex = countItem.Index + 1;

                    }
                    bool Add = true;
                    foreach (DataList validate in ListViewLocal.Items)
                    {
                        if (validate.Name.Equals(dataList.Name))
                            if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), dataList.Name), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                                Add = false;
                    }
                    if (Add)
                    {
                        AddFileDirectoryAzure(dataList, this.Azurepath, this.Localpath, countIndex, this.ListViewAzureProgress, ListViewLocal);

                        if (ListViewAzure.SelectedItems.Count > 0)
                        {
                            GridViewAzureProgress.Visibility = Visibility.Visible;
                        }
                    }
                }


            }


        }

        /// <summary>
        /// Drop Azure->Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DropListLocal_Drop(object sender, DragEventArgs e)
        {
            if (this.Localpath.Equals(string.Empty))
            {
                MessageBox.Show(ResManager.GetString("Error_SelectPath" + cons.Language) + " ", string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            foreach (DataList dataList in ListViewAzure.SelectedItems)
            {
                if (!dataList.HiddenBytes.Equals("Hidden"))
                {
                    string Inname = string.Empty;
                    string Outname = string.Empty;

                    if (!this.Localpath.Equals(string.Empty))
                        Inname = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                    if (!this.Azurepath.Equals(string.Empty))
                        Outname = this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;

                    //Get the Next Index
                    int countIndex = 0;
                    if (ListViewAzureProgress.Items.Count > 0)
                    {
                        Progress countItem = (Progress)ListViewAzureProgress.Items[ListViewAzureProgress.Items.Count - 1];
                        countIndex = countItem.Index + 1;

                    }

                    Progress progres = new Progress(dataList.Name, 0, Inname, Outname, countIndex);

                    bool Add = true;
                    foreach (Progress validate in ListViewAzureProgress.Items)
                    {
                        if (validate.OutPath.Equals(progres.OutPath) && validate.Valueprogress < 100)
                            Add = false;
                    }

                    if (Add)
                    {
                        Add = true;
                        foreach (DataList validate in ListViewLocal.Items)
                        {
                            if (validate.Name.Equals(dataList.Name))
                                if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), dataList.Name), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                                    Add = false;
                        }
                        if (Add)
                        {

                            ListViewAzureProgress.Items.Add(progres);

                            if (ListViewAzure.SelectedItems.Count > 0)
                            {
                                GridViewAzureProgress.Visibility = Visibility.Visible;
                            }
                        }
                    }
                }
                else if (dataList.HiddenBytes.Equals("Hidden"))
                {
                    //Get the Next Index
                    int countIndex = 0;
                    if (ListViewAzureProgress.Items.Count > 0)
                    {
                        Progress countItem = (Progress)ListViewAzureProgress.Items[ListViewAzureProgress.Items.Count - 1];
                        countIndex = countItem.Index + 1;

                    }
                    bool Add = true;
                    foreach (DataList validate in ListViewLocal.Items)
                    {
                        if (validate.Name.Equals(dataList.Name))
                            if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), dataList.Name), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                                Add = false;
                    }
                    if (Add)
                    {
                        AddFileDirectoryAzure(dataList, this.Azurepath, this.Localpath, countIndex, this.ListViewAzureProgress, ListViewLocal);

                        if (ListViewAzure.SelectedItems.Count > 0)
                        {
                            GridViewAzureProgress.Visibility = Visibility.Visible;
                        }
                    }
                }
            }

            //if (ListViewAzure.SelectedItems.Count > 0)
            //{
            //GridViewAzureProgress.Visibility = Visibility.Visible;
            //}


        }


        /// <summary>
        /// For TreeMenu Add Local->Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeMenuItemAzureAdd_Click(object sender, RoutedEventArgs e)
        {
            if (this.Azurepath.Equals(string.Empty))
            {
                MessageBox.Show(ResManager.GetString("Error_SelectPath" + cons.Language) + " ", string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            TreeViewItem items = (TreeViewItem)Tre_Azure.SelectedItem;

            StackPanel Oldpanpanel = (StackPanel)items.Header;
            TextBlock textblock = (TextBlock)Oldpanpanel.Children[1];


            //Get the Next Index
            int countIndex = 0;
            if (ListViewAzureProgress.Items.Count > 0)
            {
                Progress countItem = (Progress)ListViewAzureProgress.Items[ListViewAzureProgress.Items.Count - 1];
                countIndex = countItem.Index + 1;

            }
            bool Add = true;
            foreach (DataList validate in ListViewLocal.Items)
            {
                if (validate.Name.Equals(textblock.Text.Trim()))
                    if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), textblock.Text.Trim()), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                        Add = false;
            }
            if (Add)
            {
                string[] vecPath = this.Azurepath.Split('\\');
                string strPath = string.Empty;
                strPath = vecPath[0] + @"\";
                for (int i = 1; i < vecPath.Length - 1; i++)
                    if (!vecPath[i].Equals(""))
                    {
                        strPath += strPath.EndsWith(@"\") ? string.Empty : @"\";
                        strPath += vecPath[i];
                    }

                DataList dataList = new DataList(textblock.Text.Trim(), string.Empty, string.Empty, 0, string.Empty);

                AddFileDirectoryAzure(dataList, strPath, this.Localpath, countIndex, this.ListViewAzureProgress, ListViewLocal);

                GridViewAzureProgress.Visibility = Visibility.Visible;

            }



        }


        private void Download()
        {
            //Progress名を入れます
            for (int i = 0; i < ListViewAzureProgress.Items.Count; i++)
            {
                //if (DownloadFileIndex > -1)
                //    break;

                Progress progress = (Progress)ListViewAzureProgress.Items[i];

                if (progress.Valueprogress == 0 && DownloadFileIndex == -1)
                {
                    if (!progress.InPath.Equals(string.Empty))
                    {
                        //Cancel
                        if (CancelDownload)
                        {
                            CancelDownload = false;
                            DownloadFileIndex = -1;
                            return;
                        }

                        DownloadFileIndex = progress.Index;
                        progress.Valueprogress = 1;


                        string info = Azure.getInfoFile(progress.OutPath, Const.key());
                        string[] vecinfo = info.Split('|');
                        if (vecinfo[0].Equals("0"))
                        {
                            string error = string.Empty;
                            //Validate Server and Folder Download
                            try
                            {
                                //Cancel
                                if (CancelDownload)
                                {
                                    CancelDownload = false;
                                    DownloadFileIndex = -1;
                                    return;
                                }

                                error = Azure.ValidaFolderDownload(progress.OutPath, Const.key());
                                if (error.Length > 0)
                                {
                                    MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + error, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                                    ProgressValueErrorDownload(DownloadFileIndex);
                                    DownloadFileIndex = -1;
                                    return;
                                }

                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                                ProgressValueErrorDownload(DownloadFileIndex);
                                DownloadFileIndex = -1;
                                return;
                            }
                            if (error.Length == 0)
                            {
                                try
                                {
                                    //Cancel
                                    if (CancelDownload)
                                    {
                                        CancelDownload = false;
                                        DownloadFileIndex = -1;
                                        return;
                                    }

                                    Azure.getCopyToDownload(progress.OutPath, Const.key());
                                }
                                catch { }

                                bool CompletedServer = false;
                                while (!CompletedServer)
                                {
                                    //Cancel
                                    if (CancelDownload)
                                    {
                                        CancelDownload = false;
                                        CompletedServer = true;
                                        DownloadFileIndex = -1;
                                        return;
                                    }

                                    System.Threading.Thread.Sleep(3000);
                                    string infoDownloadFile = Azure.getInfoDownloadFile(System.IO.Path.GetFileName(progress.OutPath), Const.key());
                                    string[] vecinfoDownloadFile = infoDownloadFile.Split('|');
                                    if (vecinfoDownloadFile[0].Equals("0"))
                                    {
                                        if (vecinfo[vecinfo.Length - 1].Equals(vecinfoDownloadFile[vecinfoDownloadFile.Length - 1]))
                                            CompletedServer = true;
                                    }
                                    else if (vecinfoDownloadFile[0].Equals("2"))
                                    {
                                        MessageBox.Show(vecinfoDownloadFile[1], string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                                        return;
                                    }
                                }

                                CompletedServer = false;
                                while (!CompletedServer)
                                {
                                    //Cancel
                                    if (CancelDownload)
                                    {
                                        CancelDownload = false;
                                        CompletedServer = true;
                                        DownloadFileIndex = -1;
                                        return;
                                    }

                                    string NameFile = System.IO.Path.GetFileName(progress.OutPath);
                                    string infoDownloadFile = Azure.ChangeNameToDownload(NameFile, Const.key());

                                    if (infoDownloadFile.Equals(string.Empty))
                                    {
                                        CompletedServer = true;
                                    }
                                    else if (infoDownloadFile.StartsWith("2"))
                                    {
                                        infoDownloadFile = infoDownloadFile.Replace("2", string.Empty);
                                        MessageBox.Show(infoDownloadFile, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                                        return;
                                    }
                                    else
                                    {
                                        System.Threading.Thread.Sleep(5000);
                                    }
                                }



                                if (CompletedServer)
                                {


                                    string FileName = System.IO.Path.GetFileName(@progress.OutPath);
                                    string WebFile = Azure.getCopyURLDownload(FileName, Const.key());


                                    //Cancel
                                    if (CancelDownload || WebFile.Equals(string.Empty))
                                    {
                                        CancelDownload = false;
                                        CompletedServer = true;
                                        DownloadFileIndex = -1;
                                        return;
                                    }

                                    //Create Folder
                                    string strerror = comm.CreateFolder(System.IO.Path.GetDirectoryName(progress.InPath));

                                    if (strerror.Length > 0)
                                    {
                                        MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + strerror, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                                        ProgressValueErrorDownload(i);
                                        CancelDownload = false;
                                        CompletedServer = true;
                                        DownloadFileIndex = -1;
                                        return;
                                    }

                                    this.webClient = new WebClient();
                                    this.webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                                    this.webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

                                    string NewNameExt = System.IO.Path.GetExtension(progress.InPath);
                                    string NewName = progress.InPath.Replace(NewNameExt, ".zip");

                                    this.webClient.DownloadFileAsync(new Uri(WebFile), NewName);

                                    break;

                                }
                            }
                        }
                        else
                        {

                            MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + vecinfo[0], string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                            ProgressValueErrorDownload(i);
                            DownloadFileIndex = -1;
                        }
                    }
                    else
                    {
                        MessageBox.Show(ResManager.GetString("Error_SelectPath" + cons.Language) + " ", string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                        ProgressValueErrorDownload(i);
                        DownloadFileIndex = -1;

                    }
                }

            }



        }

        /// <summary>
        /// Completed Download File
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            if (CancelDownload)
            {
                //ProgressValueCancelDownload(DownloadFileIndex);

                CancelDownload = false;
                if (DownloadFileIndex > -1)
                {
                    ProgressValueCancelDownload(DownloadFileIndex);
                    //Progress progress = (Progress)ListViewAzureProgress.Items[DownloadFileIndex];

                    //    progress.Valueprogress = 100;


                    //    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                    //    {
                    //        ListViewLocal.ItemsSource = GetLocalInformationFile(Localpath);

                    //        ListViewAzureProgress.Items[DownloadFileIndex] = progress;
                    //        ListViewAzureProgress.Items.Refresh();
                    //    }));
                }
            }
            else
            {
                if (DownloadFileIndex > -1)
                {
                    //Error to download
                    Progress progress = (Progress)ListViewAzureProgress.Items[DownloadFileIndex];
                    if (progress.Valueprogress < 100)
                        ProgressValueErrorDownload(DownloadFileIndex);
                    //Can download, in change ext to original name
                    else
                    {
                        string error = comm.renameOriginalName(progress.InPath);
                        if (error.Length > 0)
                        {
                            MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + error, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                        Tre_Local.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                        {

                            string Temp = System.IO.Path.GetDirectoryName(progress.InPath);
                            string[] vecPath = System.IO.Path.GetDirectoryName(progress.InPath).Split('\\');
                            CreateItemViewSelected(Tre_Local, vecPath, ref Temp);
                            Localpath = LocalGoTXT.Text;
                            Tre_Local.Items.Refresh();

                        }));
                    }

                    //ListViewAzureProgress.Items.Refresh();
                }
            }

            if (DownloadFileIndex > -1)
            {
                Progress progress = (Progress)ListViewAzureProgress.Items[DownloadFileIndex];
                string error = Azure.ValidaFolderDownload(progress.OutPath, Const.key());

            }
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                Tre_Local.Items.Refresh();
                ListViewLocal.ItemsSource = GetLocalInformationFile(Localpath);
            }));
            DownloadFileIndex = -1;

        }

        /// <summary>
        /// Progress Download
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {


            if (DownloadFileIndex == -1)
                return;

            Progress progress = (Progress)ListViewAzureProgress.Items[DownloadFileIndex];

            progress.Valueprogress = e.ProgressPercentage;
            progress.Textprogress = e.ProgressPercentage.ToString() + "%";
            progress.ColorFill = Const.upColor(e.ProgressPercentage);


            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                //decimal de = 0;
                if (DownloadFileIndex > -1)
                {

                    if (e.ProgressPercentage == 2 ||
                        e.ProgressPercentage == 10 ||
                        e.ProgressPercentage == 20 ||
                        e.ProgressPercentage == 30 ||
                        e.ProgressPercentage == 40 ||
                        e.ProgressPercentage == 50 ||
                        e.ProgressPercentage == 60 ||
                        e.ProgressPercentage == 70 ||
                        e.ProgressPercentage == 80 ||
                        e.ProgressPercentage == 90 ||
                        e.ProgressPercentage == 100
                        )
                    {
                        ListViewAzureProgress.Items[DownloadFileIndex] = progress;
                        ListViewAzureProgress.Items.Refresh();
                    }

                }

            }));



            if (CancelDownload)
                this.webClient.CancelAsync();


        }

        /// <summary>
        /// ProgressBarのエラー変更（赤）
        /// </summary>
        /// <param name="index"></param>
        protected void ProgressValueErrorDownload(int index)
        {

            Progress progress = (Progress)ListViewAzureProgress.Items[index];

            progress.Valueprogress = 100;
            progress.Textprogress = ResManager.GetString("Error" + cons.Language);
            progress.ColorFill = Const.upColor(101);


            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                ListViewAzureProgress.Items[index] = progress;
                ListViewAzureProgress.Items.Refresh();
            }));

        }

        /// <summary>
        /// in Upload cancel/ delete line
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void CancelProssesDownload(object sender, RoutedEventArgs e)
        {

            Progress progress = ((sender as Button).Tag as Progress);

            if (progress.Valueprogress == 0)
            {
                int i = 0;
                foreach (Progress validate in ListViewAzureProgress.Items)
                {

                    if (validate.OutPath.Equals(progress.OutPath) && validate.InPath.Equals(progress.InPath) && validate.Valueprogress == 0)
                    {
                        if (DownloadFileIndex > -1)
                            if (!ProgressValueCancelDownload(i))
                                break;
                    }
                    i++;
                }
            }
            else if (progress.Valueprogress < 100)
            {
                //int i = 0;
                //foreach (Progress validate in ListViewAzureProgress.Items)
                //{
                //    if (validate.OutPath.Equals(progress.OutPath) && validate.InPath.Equals(progress.InPath) && validate.Valueprogress > 0 && validate.Valueprogress < 100)
                //    {
                if (DownloadFileIndex > -1)
                {
                    if (!ProgressValueCancelDownload(DownloadFileIndex))
                        CancelDownload = true;
                }
                else
                {

                    int i = 0;
                    foreach (Progress validate in ListViewAzureProgress.Items)
                    {
                        if (validate.OutPath.Equals(progress.OutPath) && validate.InPath.Equals(progress.InPath) && validate.Valueprogress > 0 && validate.Valueprogress < 100)
                        {
                            if (!ProgressValueCancelDownload(i))
                                CancelDownload = true;
                        }
                        i++;
                    }
                }
                //DownloadFileIndex = -1;
                //        break;
                //    }
                //    i++;
                //}
            }
            else
            {
                for (int i = 0; i < ListViewAzureProgress.Items.Count; i++)
                {
                    Progress ValideForDeleteitems = (Progress)ListViewAzureProgress.Items[i];
                    if (ValideForDeleteitems.Valueprogress < 100)
                    {
                        MessageBox.Show(ResManager.GetString("Error_Download_In_Prosses" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                }
                for (int i = 0; i < ListViewAzureProgress.Items.Count; i++)
                {
                    Progress ValideForDeleteitems = (Progress)ListViewAzureProgress.Items[i];
                    if (ValideForDeleteitems.Index.Equals(progress.Index))
                    {
                        ListViewAzureProgress.Items.RemoveAt(i);
                        return;
                    }
                }
            }



        }

        /// <summary>
        /// ProgressBarのCancel変更（黄）
        /// </summary>
        /// <param name="index"></param>
        /// <param name="name"></param>
        protected bool ProgressValueCancelDownload(int index)
        {
            bool error = false;
            try
            {
                Progress progress = (Progress)ListViewAzureProgress.Items[index];

                progress.Valueprogress = 100;
                progress.Textprogress = ResManager.GetString("Canceled" + cons.Language);
                progress.ColorFill = Const.upColor(102);


                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                {
                    ListViewAzureProgress.Items[index] = progress;
                    ListViewAzureProgress.Items.Refresh();
                }));
            }
            catch
            {
                MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + ResManager.GetString("Error_ServerBusy" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                error = true;
            }
            return error;
        }

        /// <summary>
        /// Drop Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DropListAzure_DragEnter(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent("DataList") ||
                sender == e.Source)
            {
                e.Effects = DragDropEffects.Copy;
            }
        }



        /// <summary>
        /// アップロード初め
        /// </summary>
        protected void Upload()
        {

            //Progress名を入れます
            for (int i = 0; i < ListViewLocalProgress.Items.Count; i++)
            {
                Progress progress = (Progress)ListViewLocalProgress.Items[i];

                if (progress.Valueprogress == 0)
                {
                    if (!progress.InPath.Equals(string.Empty))
                    {
                        byte[] file = Comm.ReadFile(progress.OutPath);

                        if (file != null)
                        {

                            Azure.CreateFolder(progress.InPath, Const.key());
                            SendSocket(i, progress.InPath + @"\", progress.OutPath, file);

                            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                             {
                                 ListViewAzure.ItemsSource = GetAzureInformationFile(Azurepath);

                                 string Temp = progress.InPath;
                                 string[] vecPath = progress.InPath.Split('\\');
                                 CreateItemViewSelected(Tre_Azure, vecPath, ref Temp);
                                 Azurepath = AzureGoTXT.Text;

                             }));
                        }
                        else
                        {
                            MessageBox.Show(ResManager.GetString("Error_TryRead" + cons.Language) + " " + progress.OutPath, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                        }


                    }
                    else
                    {
                        MessageBox.Show(ResManager.GetString("Error_SelectPath" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                        ProgressValueError(i);

                    }
                }

            }

        }




        /// <summary>
        /// ファイルはサーバに送ります
        /// </summary>
        /// <param name="InPath"></param>
        /// <param name="OutPath"></param>
        /// <param name="file"></param>
        protected void SendSocket(int index, string InPath, string OutPath, byte[] file)
        {
            //65536 bit is recomende for sending, in case send more bits, meaby lost the paket
            long fileLength = file.Length;
            long numPakets = 0;
            byte[] sendPaket = new byte[Const.MaxBit];
            byte[] addnewfile;


            decimal loop = 0, count = 0;

            loop = decimal.Divide(fileLength, Const.MaxBit);

            //progressBar1.Step = (int)loop + 1;

            try
            {
                string str_Error = string.Empty;
                while (count < comm.getWithOutDecimal(loop))
                {
                    addnewfile = comm.getPaket(file, long.Parse((count * Const.MaxBit).ToString()), Const.MaxBit);
                    str_Error = Azure.newfile(InPath + comm.LastNamePath(OutPath), addnewfile, long.Parse((count * Const.MaxBit).ToString()), Const.MaxBit, Const.key());
                    if (!str_Error.Equals(string.Empty))
                    {

                        break;
                    }
                    count++;
                    numPakets++;


                    // backgroundWorker1.ReportProgress((int)count * 100 / ((int)loop + 1));
                    ListViewLocalProgress.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
        {
            ProgressValueUpload(index, comm.LastNamePath(OutPath), ((int)count * 100 / ((int)loop + 1)));
        }));
                    System.Threading.Thread.Sleep(100);


                    //Cancel Upload
                    if (CancelUpload.Equals(index))
                    {
                        ProgressValueInformation(index, ResManager.GetString("Canceling" + cons.Language));
                        cancel(InPath + comm.LastNamePath(OutPath));
                        ProgressValueCancel(index);
                        return;
                    }
                }

                if (str_Error.Equals(string.Empty))
                {

                    if (loop > count)
                    {
                        long loopDecimal = long.Parse(count.ToString()) * Const.MaxBit;
                        long countDecimal = 0;

                        //while (countDecimal < loopDecimal)
                        //{
                        addnewfile = comm.getLastPaket(file, (long)loopDecimal, Const.MaxBit);
                        str_Error = Azure.newfile(InPath + comm.LastNamePath(OutPath), addnewfile, (long)loopDecimal, Const.MaxBit, Const.key());

                        countDecimal++;
                        //}
                        numPakets++;
                    }
                    //progressBar1.Step = progressBar1.Step;
                    try
                    {

                        str_Error = Azure.CreateFinishPaket(fileLength, InPath + comm.LastNamePath(OutPath), numPakets, Const.key());
                    }
                    catch
                    {
                        MessageBox.Show(ResManager.GetString("Info_ProssesEnd" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                        str_Error = string.Empty;
                    }

                    if (str_Error.Equals(string.Empty))
                    {
                        ListViewLocalProgress.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                        {
                            ProgressValueUpload(index, comm.LastNamePath(OutPath), 100);
                        }));
                    }
                }


                //エラー
                if (!str_Error.Equals(string.Empty))
                {
                    MessageBox.Show(str_Error, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    cancel(InPath + comm.LastNamePath(OutPath));
                    ProgressValueError(index);
                }
            }
            catch
            {

                cancel(InPath + comm.LastNamePath(OutPath));
                ProgressValueError(index);
            }
            finally { file = null; }
            //progressBar1.Value = 0;


        }


        /// <summary>
        /// Cancel サーバ
        /// </summary>
        /// <param name="outpath"></param>
        protected void cancel(string outpath)
        {
            Azure.Cancel(outpath, Const.key());
        }

        /// <summary>
        /// ProgressBarの変更（緑）
        /// </summary>
        /// <param name="index"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        protected void ProgressValueUpload(int index, string name, int value)
        {



            Progress progress = (Progress)ListViewLocalProgress.Items[index];
            if (progress.Name.Equals(name))
            {
                progress.Valueprogress = value;
                progress.Textprogress = value.ToString() + "%";
                progress.ColorFill = Const.upColor(value);
            }

            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
      {
          ListViewLocalProgress.Items[index] = progress;
          ListViewLocalProgress.Items.Refresh();
      }));


        }


        /// <summary>
        /// ProgressBarのエラー変更（赤）
        /// </summary>
        /// <param name="index"></param>
        protected void ProgressValueError(int index)
        {

            Progress progress = (Progress)ListViewLocalProgress.Items[index];

            progress.Valueprogress = 100;
            progress.Textprogress = ResManager.GetString("Error" + cons.Language);
            progress.ColorFill = Const.upColor(101);


            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                ListViewLocalProgress.Items[index] = progress;
                ListViewLocalProgress.Items.Refresh();
            }));

        }

        /// <summary>
        /// Visualise Download List
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ri_bt_DownloadList_Click(object sender, RoutedEventArgs e)
        {
            GridViewAzureProgress.Visibility = Visibility.Visible;
        }

        /// <summary>
        /// Visualise Uploaded List
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ri_bt_UploadList_Click(object sender, RoutedEventArgs e)
        {
            GridViewLocalProgress.Visibility = Visibility.Visible;
        }


        /// <summary>
        /// Collapse Upload List
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CollapseUploadList_Click(object sender, RoutedEventArgs e)
        {
            GridViewLocalProgress.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// Collapse Download List
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CollapseDownloadList_Click(object sender, RoutedEventArgs e)
        {
            GridViewAzureProgress.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// 削除します Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListViewLocalProgress_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Delete)
                return;

            for (int i = 0; i < ListViewLocalProgress.Items.Count; i++)
            {
                Progress progress = (Progress)ListViewLocalProgress.Items[i];
                if (progress.Valueprogress < 100)
                {
                    MessageBox.Show(ResManager.GetString("Error_Upload_In_Prosses" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }

            // for (int i = 0; i < ListViewLocalProgress.Items.Count; i++)
            // {


            while (ListViewLocalProgress.SelectedItems.Count > 0)
            {
                ListViewLocalProgress.Items.Remove(ListViewLocalProgress.SelectedItem);
            }
            //if (ListViewLocalProgress.)
            //{
            //    Progress progress = (Progress)ListViewLocalProgress.Items[i];

            //   if (progress.Valueprogress == 100)
            //        ListViewLocalProgress.Items.RemoveAt(i);

            //}

            // }

        }


        /// <summary>
        /// 削除します Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListViewAzureProgress_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Delete)
                return;

            for (int i = 0; i < ListViewAzureProgress.Items.Count; i++)
            {
                Progress progress = (Progress)ListViewAzureProgress.Items[i];
                if (progress.Valueprogress < 100)
                {
                    MessageBox.Show(ResManager.GetString("Error_Download_In_Prosses" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }

            // for (int i = 0; i < ListViewLocalProgress.Items.Count; i++)
            // {


            while (ListViewAzureProgress.SelectedItems.Count > 0)
            {
                ListViewAzureProgress.Items.Remove(ListViewAzureProgress.SelectedItem);
            }
            //if (ListViewLocalProgress.)
            //{
            //    Progress progress = (Progress)ListViewLocalProgress.Items[i];

            //   if (progress.Valueprogress == 100)
            //        ListViewLocalProgress.Items.RemoveAt(i);

            //}

            // }

        }

        /// <summary>
        /// in Upload cancel/ delete line
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void CancelProssesUpload(object sender, RoutedEventArgs e)
        {

            Progress progress = ((sender as Button).Tag as Progress);

            if (progress.Valueprogress == 0)
            {
                int i = 0;
                foreach (Progress validate in ListViewLocalProgress.Items)
                {

                    if (validate.OutPath.Equals(progress.OutPath) && validate.InPath.Equals(progress.InPath) && validate.Valueprogress == 0)
                    {
                        ProgressValueCancel(i);
                        CancelUpload = i;
                        break;
                    }
                    i++;
                }
            }
            else if (progress.Valueprogress < 100)
            {
                int i = 0;
                foreach (Progress validate in ListViewLocalProgress.Items)
                {
                    if (validate.OutPath.Equals(progress.OutPath) && validate.InPath.Equals(progress.InPath) && validate.Valueprogress > 0 && validate.Valueprogress < 100)
                    {
                        CancelUpload = i;
                        break;
                    }
                    i++;
                }
            }
            else
            {
                for (int i = 0; i < ListViewLocalProgress.Items.Count; i++)
                {
                    Progress ValideForDeleteitems = (Progress)ListViewLocalProgress.Items[i];
                    if (ValideForDeleteitems.Valueprogress < 100)
                    {
                        MessageBox.Show(ResManager.GetString("Error_Upload_In_Prosses" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                }
                for (int i = 0; i < ListViewLocalProgress.Items.Count; i++)
                {
                    Progress ValideForDeleteitems = (Progress)ListViewLocalProgress.Items[i];
                    if (ValideForDeleteitems.Index.Equals(progress.Index))
                    {
                        ListViewLocalProgress.Items.RemoveAt(i);
                        return;
                    }
                }
            }


        }




        /// <summary>
        /// ProgressBarのCancel変更（黄）
        /// </summary>
        /// <param name="index"></param>
        /// <param name="name"></param>
        protected void ProgressValueCancel(int index)
        {

            Progress progress = (Progress)ListViewLocalProgress.Items[index];

            progress.Valueprogress = 100;
            progress.Textprogress = ResManager.GetString("Canceled" + cons.Language);
            progress.ColorFill = Const.upColor(102);


            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                ListViewLocalProgress.Items[index] = progress;
                ListViewLocalProgress.Items.Refresh();
            }));
        }

        /// <summary>
        /// ProgressBarのText変更
        /// </summary>
        /// <param name="index"></param>
        /// <param name="name"></param>
        protected void ProgressValueInformation(int index, string Info)
        {

            Progress progress = (Progress)ListViewLocalProgress.Items[index];
            progress.Textprogress = Info;


            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                ListViewLocalProgress.Items[index] = progress;
                ListViewLocalProgress.Items.Refresh();
            }));
        }


        /// <summary>
        /// ListView Azure in menu config
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListViewAzure_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            DataList dataListClick = null;

            e.Handled = true;

            List<string> DeletePath = new List<string>();
            MenuItem menu = sender as MenuItem;
            if (menu != null)
                dataListClick = menu.DataContext as DataList;

            bool enabled = false;
            if (ListViewAzure.SelectedItems.Count > 0)
                enabled = true;


            //update
            menuAzureDownload.IsEnabled = enabled;
            //menuLocalUpload.Visibility = Visibility.Visible;
            //rename
            menuAzureRename.IsEnabled = enabled;
            //menuLocalRename.Visibility = Visibility.Visible;
            //Copy
            menuAzureCopy.IsEnabled = enabled;
            //menuLocalCopy.Visibility = Visibility.Visible;
            //Delete

            if (dataListClick != null)
            {
                if (dataListClick.HiddenBytes.Equals("Hidden") && enabled == true)
                    menuAzureDelete.IsEnabled = false;
                else
                    menuAzureDelete.IsEnabled = enabled;
            }
            else
                menuAzureDelete.IsEnabled = enabled;
            //menuLocalDelete.Visibility = Visibility.Visible;



            if (ListCopyAzure.Count > 0)
                //Paste
                //menuLocalPaste.Visibility = Visibility.Visible;
                menuAzurePaste.IsEnabled = true;
            else
                //Paste
                //menuLocalPaste.Visibility = Visibility.Collapsed;
                menuAzurePaste.IsEnabled = false;



        }


        /// <summary>
        /// ListView Local in menu config
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListViewLocal_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            DataList dataListClick = null;

            e.Handled = true;

            List<string> DeletePath = new List<string>();
            MenuItem menu = sender as MenuItem;
            if (menu != null)
                dataListClick = menu.DataContext as DataList;

            bool enabled = false;
            if (ListViewLocal.SelectedItems.Count > 0)
                enabled = true;


            //update
            menuLocalUpload.IsEnabled = enabled;
            //menuLocalUpload.Visibility = Visibility.Visible;
            //rename
            menuLocalRename.IsEnabled = enabled;
            //menuLocalRename.Visibility = Visibility.Visible;
            //Copy
            menuLocalCopy.IsEnabled = enabled;
            //menuLocalCopy.Visibility = Visibility.Visible;
            //Delete
            if (dataListClick != null)
            {
                if (dataListClick.HiddenBytes.Equals("Hidden") && enabled == true)
                    menuLocalDelete.IsEnabled = false;
                else
                    menuLocalDelete.IsEnabled = enabled;
            }
            else
                menuLocalDelete.IsEnabled = enabled;
            //menuLocalDelete.Visibility = Visibility.Visible;



            if (ListCopy.Count > 0)
                //Paste
                //menuLocalPaste.Visibility = Visibility.Visible;
                menuLocalPaste.IsEnabled = true;
            else
                //Paste
                //menuLocalPaste.Visibility = Visibility.Collapsed;
                menuLocalPaste.IsEnabled = false;



        }



        /// <summary>
        /// For TreeMenu Add Local->Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeMenuItemAdd_Click(object sender, RoutedEventArgs e)
        {
            if (this.Azurepath.Equals(string.Empty))
            {
                MessageBox.Show(ResManager.GetString("Error_SelectPath" + cons.Language) + " ", string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            TreeViewItem items = (TreeViewItem)Tre_Local.SelectedItem;

            StackPanel Oldpanpanel = (StackPanel)items.Header;
            TextBlock textblock = (TextBlock)Oldpanpanel.Children[1];


            //Get the Next Index
            int countIndex = 0;
            if (ListViewLocalProgress.Items.Count > 0)
            {
                Progress countItem = (Progress)ListViewLocalProgress.Items[ListViewLocalProgress.Items.Count - 1];
                countIndex = countItem.Index + 1;

            }
            bool Add = true;
            foreach (DataList validate in ListViewAzure.Items)
            {
                if (validate.Name.Equals(textblock.Text.Trim()))
                    if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), textblock.Text.Trim()), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                        Add = false;
            }
            if (Add)
            {
                string[] vecPath = this.Localpath.Split('\\');
                string strPath = string.Empty;
                strPath = vecPath[0] + @"\";
                for (int i = 1; i < vecPath.Length - 1; i++)
                    if (!vecPath[i].Equals(""))
                    {
                        strPath += strPath.EndsWith(@"\") ? string.Empty : @"\";
                        strPath += vecPath[i];
                    }

                DataList dataList = new DataList(textblock.Text.Trim(), string.Empty, string.Empty, 0, string.Empty);
                AddFileDirectory(dataList, strPath, this.Azurepath, countIndex, this.ListViewLocalProgress, ListViewAzure);


                GridViewLocalProgress.Visibility = Visibility.Visible;

            }



        }

        /// <summary>
        /// メニューアップロード追加 Local->Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemAdd_Click(object sender, RoutedEventArgs e)
        {
            //MenuItem menu = sender as MenuItem;
            //DataList dataListClick = menu.DataContext as DataList;

            //GridViewLocalProgress.Visibility = Visibility.Visible;

            // bool igualName = false;
            if (this.Localpath.Equals(string.Empty))
            {
                MessageBox.Show(ResManager.GetString("Error_SelectPath" + cons.Language) + " ", string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            foreach (DataList dataList in ListViewLocal.SelectedItems)
            {
                if (!dataList.HiddenBytes.Equals("Hidden"))
                {
                    string Inname = string.Empty;
                    string Outname = string.Empty;

                    if (!this.Localpath.Equals(string.Empty))
                        Outname = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                    if (!this.Azurepath.Equals(string.Empty))
                        Inname = this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\");// + dataList.Name;

                    //if (dataListClick.Name.Equals(dataList.Name))
                    //    igualName = true;

                    //Get the Next Index
                    int countIndex = 0;
                    if (ListViewLocalProgress.Items.Count > 0)
                    {
                        Progress countItem = (Progress)ListViewLocalProgress.Items[ListViewLocalProgress.Items.Count - 1];
                        countIndex = countItem.Index + 1;

                    }

                    Progress progres = new Progress(dataList.Name, 0, Inname, Outname, countIndex);

                    bool Add = true;
                    foreach (Progress validate in ListViewLocalProgress.Items)
                    {
                        if (validate.OutPath.Equals(progres.OutPath) && validate.Valueprogress < 100)
                            Add = false;
                    }
                    if (Add)
                    {
                        Add = true;
                        foreach (DataList validate in ListViewAzure.Items)
                        {
                            if (validate.Name.Equals(dataList.Name))
                                if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), dataList.Name), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                                    Add = false;
                        }
                        if (Add)
                        {
                            ListViewLocalProgress.Items.Add(progres);

                            if (ListViewLocal.SelectedItems.Count > 0)
                            {
                                GridViewLocalProgress.Visibility = Visibility.Visible;
                            }
                        }
                    }
                }
                else if (dataList.HiddenBytes.Equals("Hidden"))
                {
                    //Get the Next Index
                    int countIndex = 0;
                    if (ListViewLocalProgress.Items.Count > 0)
                    {
                        Progress countItem = (Progress)ListViewLocalProgress.Items[ListViewLocalProgress.Items.Count - 1];
                        countIndex = countItem.Index + 1;

                    }
                    bool Add = true;
                    foreach (DataList validate in ListViewAzure.Items)
                    {
                        if (validate.Name.Equals(dataList.Name))
                            if (MessageBox.Show(string.Format(ResManager.GetString("Info_AlredyLocalExist" + cons.Language), dataList.Name), string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                                Add = false;
                    }
                    if (Add)
                    {
                        AddFileDirectory(dataList, this.Localpath, this.Azurepath, countIndex, this.ListViewLocalProgress, ListViewAzure);

                        if (ListViewLocal.SelectedItems.Count > 0)
                        {
                            GridViewLocalProgress.Visibility = Visibility.Visible;
                        }
                    }
                }


            }
            //セレックとしていない場合
            //if (!igualName)
            //{

            //    string Inname = string.Empty;
            //    string Outname = string.Empty;

            //    if (!this.Localpath.Equals(string.Empty))
            //        Outname = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name;
            //    if (!this.Azurepath.Equals(string.Empty))
            //        Inname = this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name;

            //    if (dataListClick.Name.Equals(dataListClick.Name))
            //        igualName = true;

            //    //Get the Next Index
            //    int countIndex = 0;
            //    if (ListViewLocalProgress.Items.Count > 0)
            //    {
            //        Progress countItem = (Progress)ListViewLocalProgress.Items[ListViewLocalProgress.Items.Count - 1];
            //        countIndex = countItem.Index++;

            //    }

            //    Progress progres = new Progress(dataListClick.Name, 0, Inname, Outname, countIndex);

            //    bool Add = true;
            //    foreach (Progress validate in ListViewLocalProgress.Items)
            //    {
            //        if (validate.OutPath.Equals(progres.OutPath) && validate.Valueprogress < 100)
            //            Add = false;
            //    }

            //    if (Add)
            //        ListViewLocalProgress.Items.Add(progres);

            //}





        }


        /// <summary>
        /// Azureのファイルを削除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemDeleteAzure_Click(object sender, RoutedEventArgs e)
        {
            List<string> DeletePath = new List<string>();
            //MenuItem menu = sender as MenuItem;
            //DataList dataListClick = menu.DataContext as DataList;
            try
            {
                //bool igualName = false;
                foreach (DataList dataList in ListViewAzure.SelectedItems)
                {
                    DeletePath.Add(this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name);
                    //if (dataListClick.Name.Equals(dataList.Name))
                    //    igualName = true;
                }
                //セレックとしていない場合
                //if (!igualName)
                //{
                //    DeletePath.Add(this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name);
                //}

                string strDataListForDelete = Environment.NewLine; ;

                foreach (string path in DeletePath)
                    strDataListForDelete += path + Environment.NewLine;

                if (MessageBox.Show(ResManager.GetString("Info_DeleteFile" + cons.Language) + strDataListForDelete, string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {

                    List<DataList> dataListItems = new List<DataList>();
                    foreach (DataList dataList in ListViewAzure.SelectedItems)
                    {
                        dataListItems.Add(dataList);
                    }

                    foreach (DataList dataList in dataListItems)
                    {
                        if (!dataList.HiddenBytes.Equals("Hidden"))
                        {
                            string error = Azure.DeleteFile(this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name, Const.key());
                            if (error.Length > 0)
                                MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + error + "[" + this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name + "]", string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            try
                            {
                                AzureGoTXT.Text = this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                                string[] vecPath = AzureGoTXT.Text.Split('\\');
                                Expanded(Tre_Azure, vecPath, ref Azurepath);
                                treeViewAzureDeleteFolder(sender, e);
                                AzureGoTXT.Text = Azurepath;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language).Trim() + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                                AzureGoTXT.Text = Azurepath;
                            }
                        }

                    }

                }
                else
                { return; }


                ListViewAzure.ItemsSource = GetAzureInformationFile(Azurepath);
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error); }

        }


        /// <summary>
        /// Localのファイルを削除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
        {
            List<string> DeletePath = new List<string>();


            //bool igualName = false;
            foreach (DataList dataList in ListViewLocal.SelectedItems)
            {
                DeletePath.Add(this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name);

            }

            string strDataListForDelete = Environment.NewLine; ;

            foreach (string path in DeletePath)
                strDataListForDelete += path + Environment.NewLine;

            if (MessageBox.Show(ResManager.GetString("Info_DeleteFile" + cons.Language) + strDataListForDelete, string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {



                List<DataList> dataListItems = new List<DataList>();
                foreach (DataList dataList in ListViewLocal.SelectedItems)
                {
                    dataListItems.Add(dataList);
                }

                foreach (DataList dataList in dataListItems)
                {

                    if (!dataList.HiddenBytes.Equals("Hidden"))
                    {
                        try
                        {
                            File.Delete(this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name);
                        }
                        catch (Exception ex)
                        { MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error); }
                    }
                    else
                    {
                        try
                        {
                            LocalGoTXT.Text = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name;
                            string[] vecPath = LocalGoTXT.Text.Split('\\');
                            Expanded(Tre_Local, vecPath, ref Localpath);
                            treeViewLocalDeleteFolder(sender, e);
                            LocalGoTXT.Text = Localpath;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language).Trim() + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                            LocalGoTXT.Text = Localpath;
                        }
                    }
                }
                ListViewLocal.ItemsSource = GetLocalInformationFile(Localpath);

            }
        }


        /// <summary>
        /// Localのファイルをコピー
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
        {
            MenuItem menu = sender as MenuItem;
            DataList dataListClick = menu.DataContext as DataList;
            ListCopy.Clear();

            try
            {
                //bool igualName = false;
                foreach (DataList dataList in ListViewLocal.SelectedItems)
                {
                    if (!dataList.HiddenBytes.Equals("Hidden"))
                        ListCopy.Add(this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name);
                    else
                    {

                        ListCopy.Add(this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name);

                    }
                    //if (dataListClick.Name.Equals(dataList.Name))
                    //    igualName = true;
                }
                //セレックとしていない場合
                //if (!igualName)
                //{
                //    ListCopy.Add(this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name);
                //}

            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error); }

        }

        /// <summary>
        /// Localのファイルをコピー
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemAzureCopy_Click(object sender, RoutedEventArgs e)
        {
            //MenuItem menu = sender as MenuItem;
            //DataList dataListClick = menu.DataContext as DataList;
            ListCopyAzure.Clear();
            try
            {
                // bool igualName = false;
                foreach (DataList dataList in ListViewAzure.SelectedItems)
                {
                    if (!dataList.HiddenBytes.Equals("Hidden"))
                        ListCopyAzure.Add(this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name);
                    else
                    {

                        ListCopyAzure.Add(this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataList.Name);

                    }
                    //if (dataListClick.Name.Equals(dataList.Name))
                    //    igualName = true;
                }
                //セレックとしていない場合
                //if (!igualName)
                //{
                //    ListCopyAzure.Add(this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name);
                //}

            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error); }

        }

        /// <summary>
        /// Paste Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemPaste_Click(object sender, RoutedEventArgs e)
        {
            popup.Visibility = Visibility.Visible;
            Paste paste = new Paste(ListCopy, this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\"));
            if (paste.ShowDialog() == true)
                ListViewLocal.ItemsSource = GetLocalInformationFile(Localpath);

            Tre_Local.Items.Clear();
            initializeListFile();

            LocalGoTXT.Text = LocalGoTXT.Text.Trim();
            LocalGoTXT.Text = LocalGoTXT.Text.Replace("/", @"\");
            try
            {
                string[] vecPath = LocalGoTXT.Text.Split('\\');
                Expanded(Tre_Local, vecPath, ref Localpath);
                LocalGoTXT.Text = Localpath;
            }
            catch (Exception ex)
            { MessageBox.Show(ResManager.GetString("Error" + cons.Language).Trim() + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Information); }
            popup.Visibility = Visibility.Hidden;
        }



        /// <summary>
        /// Paste Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemAzurePaste_Click(object sender, RoutedEventArgs e)
        {
            popup.Visibility = Visibility.Visible;
            PasteAzure paste = new PasteAzure(ListCopyAzure, this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\"), Azure);
            if (paste.ShowDialog() == true)
                ListViewAzure.ItemsSource = GetAzureInformationFile(Azurepath);


            foreach (string CopyFolder in ListCopyAzure)
            {
                if (System.IO.Path.GetExtension(CopyFolder).Equals(string.Empty))
                {
                    GetListVHD.ArrayOfString listFiles;
                    listFiles = Azure.getFiles(comm.FirstPath(Azurepath), Const.key());

                    foreach (string directory in listFiles)
                    {

                        string[] vecdirectory = directory.Split('|');
                        if (vecdirectory[2].Equals("Directory"))
                        {

                            string temp = Azurepath + (Azurepath.EndsWith(@"\") ? string.Empty : @"\") + System.IO.Path.GetFileName(vecdirectory[0]);
                            string[] vectemp = temp.Split('\\');
                            CreateItemViewSelected(Tre_Azure, vectemp, ref temp);


                            GetListVHD.ArrayOfString listFiles2;
                            listFiles2 = Azure.getFiles(comm.FirstPath(temp), Const.key());
                            foreach (string directory2 in listFiles2)
                            {
                                string[] vecdirectory2 = directory2.Split('|');
                                if (vecdirectory2[2].Equals("Directory"))
                                {

                                    string temp2 = temp + (temp.EndsWith(@"\") ? string.Empty : @"\") + System.IO.Path.GetFileName(vecdirectory2[0]);
                                    string[] vectemp2 = temp2.Split('\\');

                                    CreateItemViewSelected(Tre_Azure, vectemp2, ref temp2);
                                }
                            }
                        }
                    }
                }
            }
            AzureGoTXT.Text = Azurepath;
            string[] vecPath = AzureGoTXT.Text.Split('\\');
            Expanded(Tre_Azure, vecPath, ref Azurepath);
            AzureGoTXT.Text = Azurepath;

            popup.Visibility = Visibility.Hidden;
        }



        //******************** Transparent ********************************//
        [StructLayout(LayoutKind.Sequential)]
        private struct MARGINS
        {
            public int cxLeftWidth;      // width of left border that retains its size
            public int cxRightWidth;     // width of right border that retains its size
            public int cyTopHeight;      // height of top border that retains its size
            public int cyBottomHeight;   // height of bottom border that retains its size
        };

        [DllImport("DwmApi.dll")]
        private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset);

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowInteropHelper windowInteropHelper = new WindowInteropHelper(this);
            IntPtr myHwnd = windowInteropHelper.Handle;
            HwndSource mainWindowSrc = System.Windows.Interop.HwndSource.FromHwnd(myHwnd);

            mainWindowSrc.CompositionTarget.BackgroundColor = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);

            MARGINS margins = new MARGINS()
            {
                cxLeftWidth = -1,
                cxRightWidth = -1,
                cyBottomHeight = -1,
                cyTopHeight = -1
            };

            DwmExtendFrameIntoClientArea(myHwnd, ref margins);
        }




        //******************** Transparent END ********************************//

        /// <summary>
        /// Ribbon.QuickAccessToolBar visible = false
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ri_Menu_Loaded(object sender, RoutedEventArgs e)
        {
            Grid child = VisualTreeHelper.GetChild((DependencyObject)sender, 0) as Grid;
            if (child != null)
            {
                child.RowDefinitions[0].Height = new GridLength(0);
            }
        }

        private void Ri_bt_AddConfig_Click(object sender, RoutedEventArgs e)
        {
            //popupAdd.Visibility = Visibility.Visible;


            popupAddFrame.Source = null;
            popupAddFrame.Source = new Uri("AddConnection.xaml", UriKind.Relative);
            popupAddFrame.NavigationService.Refresh();

        }

        private void Close_popupAdd_Click(object sender, RoutedEventArgs e)
        {
            // popupAdd.Visibility = Visibility.Hidden;

        }

        private void Ri_bt_VhdCreate_Click(object sender, RoutedEventArgs e)
        {
            //popupVhdUpload.Visibility = Visibility.Visible;
            popupVhdVHDAdd.Source = null;
            popupVhdVHDAdd.Source = new Uri("VHDCreate.xaml", UriKind.Relative);
            popupVhdVHDAdd.NavigationService.Refresh();

        }


        private void Ri_bt_VhdUpload_Click(object sender, RoutedEventArgs e)
        {
            //popupVhdUpload.Visibility = Visibility.Visible;
            popupVhdUpload.Source = null;
            popupVhdUpload.Source = new Uri("VHDUpload.xaml", UriKind.Relative);
            popupVhdUpload.NavigationService.Refresh();

        }

        private void Close_popupVhdUpload_Click(object sender, RoutedEventArgs e)
        {
            //popupVhdUpload.Visibility = Visibility.Hidden;
        }

        private void Close_popupVHDBackupDelete_Click(object sender, RoutedEventArgs e)
        {



            //popupVHDBackupDelete.Visibility = Visibility.Hidden;
        }

        private void Ri_bt_BackupDelete_Click(object sender, RoutedEventArgs e)
        {
            popupVHDBackupDelete.Source = null;
            popupVHDBackupDelete.Source = new Uri("VHDBackupDelete.xaml", UriKind.Relative);
            popupVHDBackupDelete.NavigationService.Refresh();
            //popupVHDBackupDelete.Visibility = Visibility.Visible;

        }


        /// <summary>
        /// rename items in Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemAzureRename_Click(object sender, RoutedEventArgs e)
        {
            //MenuItem menu = sender as MenuItem;
            //DataList dataListClick = menu.DataContext as DataList;
            List<DataList> ListView = new List<DataList>();


            DataList dataListClick = ListViewAzure.SelectedItem as DataList;

            if (dataListClick == null)
                return;

            dataListClick.Rename = "Visible";

            foreach (DataList ViewAzure in ListViewAzure.ItemsSource)
            {
                if (dataListClick.Name.Equals(ViewAzure.Name))
                {
                    dataListClick.RenameText = ViewAzure.Name;
                    ListView.Add(dataListClick);
                }
                else
                    ListView.Add(ViewAzure);
            }

            ListViewAzure.ItemsSource = ListView;
        }

        /// <summary>
        /// rename items in local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItemRename_Click(object sender, RoutedEventArgs e)
        {
            //MenuItem menu = sender as MenuItem;
            //DataList dataListClick = menu.DataContext as DataList;
            List<DataList> ListView = new List<DataList>();


            DataList dataListClick = ListViewLocal.SelectedItem as DataList;

            if (dataListClick == null)
                return;

            dataListClick.Rename = "Visible";

            foreach (DataList ViewLocal in ListViewLocal.ItemsSource)
            {
                if (dataListClick.Name.Equals(ViewLocal.Name))
                {
                    dataListClick.RenameText = ViewLocal.Name;
                    ListView.Add(dataListClick);
                }
                else
                    ListView.Add(ViewLocal);
            }

            ListViewLocal.ItemsSource = ListView;
        }

        /// <summary>
        /// Rename Cancel Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RenameCancel_Click(object sender, RoutedEventArgs e)
        {
            Button menu = sender as Button;
            DataList dataListClick = menu.DataContext as DataList;
            List<DataList> ListView = new List<DataList>();


            dataListClick.Rename = "Hidden";
            foreach (DataList ViewLocal in ListViewLocal.ItemsSource)
            {
                if (dataListClick.Name.Equals(ViewLocal.Name))
                    ListView.Add(dataListClick);
                else
                    ListView.Add(ViewLocal);
            }

            ListViewLocal.ItemsSource = ListView;
        }

        /// <summary>
        /// Rename Cancel Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RenameAzureCancel_Click(object sender, RoutedEventArgs e)
        {
            Button menu = sender as Button;
            DataList dataListClick = menu.DataContext as DataList;
            List<DataList> ListView = new List<DataList>();


            dataListClick.Rename = "Hidden";
            foreach (DataList ViewAzure in ListViewAzure.ItemsSource)
            {
                if (dataListClick.Name.Equals(ViewAzure.Name))
                    ListView.Add(dataListClick);
                else
                    ListView.Add(ViewAzure);
            }

            ListViewAzure.ItemsSource = ListView;
        }


        /// <summary>
        /// Rename Change Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RenameSave_Click(object sender, RoutedEventArgs e)
        {
            Button menu = sender as Button;
            DataList dataListClick = menu.DataContext as DataList;
            List<DataList> ListView = new List<DataList>();



            foreach (DataList ViewLocal in ListViewLocal.ItemsSource)
            {
                if (dataListClick.Name.Equals(ViewLocal.Name))
                {
                    try
                    {
                        //File
                        if (!ViewLocal.HiddenBytes.Equals("Hidden"))
                            System.IO.File.Move(this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name, this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.RenameText);
                        else
                        {

                            //if selected 
                            if (TvLocalBK != null)
                            {
                                MessageBox.Show(ResManager.GetString("Error" + cons.Language) + ": " + ResManager.GetString("Info_Renombrar" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }

                            //Directory
                            string oldpathname = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name;
                            string newpathname = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.RenameText;
                            oldpathname = oldpathname.Trim();
                            newpathname = newpathname.Trim();
                            //oldpathname=oldpathname.Replace(" ", "%");
                            //newpathname = newpathname.Replace(" ", "%");
                            System.IO.Directory.Move(oldpathname, newpathname);

                            //TreeViewItem Tree = (TreeViewItem)Tre_Local.SelectedItem;

                            string path = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name;
                            string Newpath = this.Localpath + (this.Localpath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.RenameText;
                            string[] vecpath = path.Split('\\');

                            ChangeNameItemView(Tre_Local, ref vecpath, Newpath, dataListClick.Name, dataListClick.RenameText);

                        }
                        dataListClick.Name = dataListClick.RenameText;
                        dataListClick.Rename = "Hidden";
                        ListView.Add(dataListClick);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ResManager.GetString("Error" + cons.Language) + ": " + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                }
                else
                    ListView.Add(ViewLocal);
            }

            ListViewLocal.ItemsSource = ListView;
        }

        /// <summary>
        /// Rename Change Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RenameAzureSave_Click(object sender, RoutedEventArgs e)
        {
            Button menu = sender as Button;
            DataList dataListClick = menu.DataContext as DataList;
            List<DataList> ListView = new List<DataList>();



            foreach (DataList ViewAzure in ListViewAzure.ItemsSource)
            {
                if (dataListClick.Name.Equals(ViewAzure.Name))
                {
                    try
                    {
                        string error = string.Empty;
                        if (!ViewAzure.HiddenBytes.Equals("Hidden"))

                            error = Azure.MoveFile(this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name, this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.RenameText, Const.key());
                        else
                        {
                            //if selected 
                            if (TvAzureBK != null)
                            {
                                MessageBox.Show(ResManager.GetString("Error" + cons.Language) + ": " + ResManager.GetString("Info_Renombrar" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }


                            string path = this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.Name;
                            string Newpath = this.Azurepath + (this.Azurepath.EndsWith(@"\") ? string.Empty : @"\") + dataListClick.RenameText;
                            path = path.Trim();
                            Newpath = Newpath.Trim();
                            error = Azure.MoveFolder(path, Newpath, Const.key());

                            if (error.Length == 0)
                            {

                                string[] vecpath = path.Split('\\');

                                ChangeNameItemView(Tre_Azure, ref vecpath, Newpath, dataListClick.Name, dataListClick.RenameText);


                            }
                        }
                        if (!error.Equals(string.Empty))
                        {
                            MessageBox.Show(error, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        dataListClick.Name = dataListClick.RenameText;
                        dataListClick.Rename = "Hidden";
                        ListView.Add(dataListClick);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                }
                else
                    ListView.Add(ViewAzure);
            }

            ListViewAzure.ItemsSource = ListView;
        }

        /// <summary>
        /// Closed 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            try
            {
                System.Threading.Thread.Sleep(1000);
                threadDownload.Abort();
                threadUpload.Abort();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ResManager.GetString("Error_Closed" + cons.Language) + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }


        private void OnListViewItemPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {

            e.Handled = true;
        }


        /// <summary>
        /// 再Azureドライブを取っています
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ri_bt_Refresht_Click(object sender, RoutedEventArgs e)
        {
            //Azure            
            GetListVHD.ArrayOfString ListVHD = null;
            //popup
            popup.Visibility = Visibility.Visible;

            Reload fsplash = new Reload();

            Tre_Azure.Items.Clear();            
            BackgraoundAzure.Text = string.Empty;
            AzureGoTXT.Text = string.Empty;
            ListViewAzure.Items.Clear();

            if (fsplash.ShowDialog() == false) this.Close();
            ListVHD = fsplash.ListVHD;

            if (ListVHD != null)
                foreach (string path in ListVHD)
                {
                    TreeViewItem Item = CreateTreeViewItem(string.Empty, path, "Image/TreeView/", "Private.ico");
                    Item.Expanded += new RoutedEventHandler(treeViewAzure_Expand);

                    List<string> SubFolder = getListDirectoryAzure(path);
                    if (SubFolder.Count > 0)
                    {
                        foreach (string dir in SubFolder)
                        {
                            TreeViewItem ItemChir = CreateTreeViewItem(dir, comm.LastNamePath(dir), "Image/TreeView/", "CloseFolder.ico");
                            ItemChir.Expanded += new RoutedEventHandler(treeViewAzure_Expand);

                            Item.Items.Add(ItemChir);
                        }

                    }

                    Tre_Azure.Items.Add(Item);
                }

            //popup
            popup.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// TreeView Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SolutionTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeViewItem SelectedItem = Tre_Local.SelectedItem as TreeViewItem;

            Tre_Local.ContextMenu = Tre_Local.Resources["FolderContext"] as System.Windows.Controls.ContextMenu;
        }

        /// <summary>
        /// TreeView Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SolutionTreeAzure_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeViewItem SelectedItem = Tre_Azure.SelectedItem as TreeViewItem;

            Tre_Azure.ContextMenu = Tre_Azure.Resources["FolderContext"] as System.Windows.Controls.ContextMenu;
        }

        private TreeViewItem TvLocalBK = null;
        private TreeViewItem TvAzureBK = null;

        /// <summary>
        /// treeviwe Local Rename
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewLocalRenameFolder(object sender, RoutedEventArgs e)
        {
            //if selected 
            if (TvLocalBK == null)
                TvLocalBK = Tre_Local.SelectedItem as TreeViewItem;
            else
            {
                return;
            }

            TreeViewItem TvLocal = Tre_Local.SelectedItem as TreeViewItem;

            StackPanel Oldpan = (StackPanel)TvLocal.Header;
            StackPanel pan = new StackPanel();
            TextBlock text = (TextBlock)Oldpan.Children[1];

            if (!TvLocal.Tag.Equals(string.Empty) && !text.Text.Equals(string.Empty))
            {
                pan.Orientation = Orientation.Horizontal;
                Stream iconstm = this._MakeIconStream("CloseFolder.ico");
                IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                //IconBitmapDecoder icon = new IconBitmapDecoder(new Uri(System.IO.Path.Combine("Image/TreeView/", "CloseFolder.ico"), UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);                 
                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                image.Height = Const.TreeIcoSize;
                image.Source = icon.Frames[0];
                pan.Children.Add(image);
            }
            else
            {
                return;
            }

            TextBox textbox = new TextBox();
            textbox.Text = text.Text;

            textbox.Select(0, text.Text.Length);
            FocusManager.SetFocusedElement(this, textbox);
            textbox.SelectionStart = 1;
            textbox.SelectAll();
            textbox.Focus();


            textbox.KeyUp += new KeyEventHandler(TreeViewSaveLocal_KeyUp);

            TextBlock textblock = new TextBlock();
            textblock.Tag = text.Text;

            pan.Children.Add(textblock);
            pan.Children.Add(textbox);
            TvLocal.Header = pan;


        }

        /// <summary>
        /// treeviwe Azure Rename
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewAzureRenameFolder(object sender, RoutedEventArgs e)
        {
            //if selected 
            if (TvAzureBK == null)
                TvAzureBK = Tre_Azure.SelectedItem as TreeViewItem;
            else
            {
                return;
            }

            TreeViewItem TvAzure = Tre_Azure.SelectedItem as TreeViewItem;

            StackPanel Oldpan = (StackPanel)TvAzure.Header;
            StackPanel pan = new StackPanel();
            TextBlock text = (TextBlock)Oldpan.Children[1];

            if (!TvAzure.Tag.Equals(string.Empty) && !text.Text.Equals(string.Empty))
            {
                pan.Orientation = Orientation.Horizontal;
                Stream iconstm = this._MakeIconStream("CloseFolder.ico");
                IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                //IconBitmapDecoder icon = new IconBitmapDecoder(new Uri(System.IO.Path.Combine("Image/TreeView/", "CloseFolder.ico"), UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);                 
                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                image.Height = Const.TreeIcoSize;
                image.Source = icon.Frames[0];
                pan.Children.Add(image);
            }
            else
            {
                TvAzureBK = null;
                return;
            }


           
            TextBox textbox = new TextBox();
            textbox.Text = text.Text;            
            textbox.Select(0, text.Text.Length);
            
            FocusManager.SetFocusedElement(this, textbox);
            textbox.SelectionStart = 1;
            textbox.SelectAll();
            textbox.Focus();


            textbox.KeyUp += new KeyEventHandler(TreeViewSaveAzure_KeyUp);            

            TextBlock textblock = new TextBlock();
            textblock.Tag = text.Text;

            pan.Children.Add(textblock);
            pan.Children.Add(textbox);            
            TvAzure.Header = pan;

            
        }

        /// <summary>
        /// treeviwe Local Add
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewLocalAddFolder(object sender, RoutedEventArgs e)
        {
            //if selected 
            if (TvLocalBK != null)
            {
                return;
            }
            try
            {
                TreeViewItem TvLocal = Tre_Local.SelectedItem as TreeViewItem;

                StackPanel Oldpan = (StackPanel)TvLocal.Header;
                StackPanel pan = new StackPanel();
                TextBlock text = (TextBlock)Oldpan.Children[1];

                string DriverPath = string.Empty;
                if (!TvLocal.Tag.ToString().Trim().Equals(string.Empty))
                    DriverPath = TvLocal.Tag.ToString().Trim();
                else
                    DriverPath = text.Text.Trim();

                string FolderName = GetNewFolder(DriverPath + (DriverPath.EndsWith(@"\") ? string.Empty : @"\"), "New File");

                string[] vecFolderName = FolderName.Split('|');
                if (vecFolderName[0].Equals("1"))
                {
                    MessageBox.Show(ResManager.GetString("Error" + cons.Language) + ": " + vecFolderName[0], string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                Directory.CreateDirectory(vecFolderName[1]);

                string[] vecNameDirectory = vecFolderName[1].Split('\\');

                TreeViewItem ItemChir = CreateTreeViewItem(vecFolderName[1], vecNameDirectory[vecNameDirectory.Length - 1], "Image/TreeView/", "CloseFolder.ico");
                ItemChir.Expanded += new RoutedEventHandler(treeViewLocal_Expand);
                TvLocal.Items.Add(ItemChir);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ResManager.GetString("Error" + cons.Language) + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
            }

        }


        /// <summary>
        /// treeviwe Azure Add
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewAzureAddFolder(object sender, RoutedEventArgs e)
        {
            //if selected 
            if (TvAzureBK != null)
            {
                return;
            }
            try
            {
                TreeViewItem TvAzure = Tre_Azure.SelectedItem as TreeViewItem;

                StackPanel Oldpan = (StackPanel)TvAzure.Header;
                StackPanel pan = new StackPanel();
                TextBlock text = (TextBlock)Oldpan.Children[1];

                string DriverPath = string.Empty;
                if (!TvAzure.Tag.ToString().Trim().Equals(string.Empty))
                    DriverPath = TvAzure.Tag.ToString().Trim();
                else
                    DriverPath = text.Text.Trim();

                string FolderName = Azure.GetNewFolder(DriverPath + (DriverPath.EndsWith(@"\") ? string.Empty : @"\"), "New File", Const.key());

                string[] vecFolderName = FolderName.Split('|');
                if (vecFolderName[0].Equals("1"))
                {
                    MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + vecFolderName[0], string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                string error = Azure.CreateFolder(vecFolderName[1], Const.key());
                if (error.Length > 0)
                {
                    MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + error, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                string[] vecNameDirectory = vecFolderName[1].Split('\\');

                TreeViewItem ItemChir = CreateTreeViewItem(vecFolderName[1], vecNameDirectory[vecNameDirectory.Length - 1], "Image/TreeView/", "CloseFolder.ico");
                ItemChir.Expanded += new RoutedEventHandler(treeViewAzure_Expand);
                TvAzure.Items.Add(ItemChir);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
            }

        }

        /// <summary>
        /// treeviwe Local Delete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewLocalDeleteFolder(object sender, RoutedEventArgs e)
        {
            //if selected 
            if (TvLocalBK != null)
            {
                return;
            }
            try
            {
                TreeViewItem TvLocal = Tre_Local.SelectedItem as TreeViewItem;

                StackPanel Oldpan = (StackPanel)TvLocal.Header;
                StackPanel pan = new StackPanel();
                TextBlock text = (TextBlock)Oldpan.Children[1];


                if (TvLocal.Tag.ToString().Trim().Equals(string.Empty))
                {
                    MessageBox.Show(ResManager.GetString("Error_Deleting_File" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                //Delete Directory
                Directory.Delete(TvLocal.Tag.ToString().Trim(), true);


                //Delete at treeview
                int index = Tre_Local.Items.IndexOf(Tre_Local.SelectedItem);
                TreeViewItem parent = (Tre_Local.SelectedItem as TreeViewItem).Parent as TreeViewItem;

                if (index < 0)
                {
                    index = parent.Items.IndexOf(Tre_Local.SelectedItem);
                }

                if (index > -1)
                {
                    parent.Items.RemoveAt(index);
                }



            }
            catch (Exception ex)
            {
                MessageBox.Show(ResManager.GetString("Error" + cons.Language) + ": " + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
            }

        }

        /// <summary>
        /// treeviwe Azure Delete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewAzureDeleteFolder(object sender, RoutedEventArgs e)
        {
            //if selected 
            if (TvLocalBK != null)
            {
                return;
            }
            try
            {
                TreeViewItem TvAzure = Tre_Azure.SelectedItem as TreeViewItem;

                StackPanel Oldpan = (StackPanel)TvAzure.Header;
                StackPanel pan = new StackPanel();
                TextBlock text = (TextBlock)Oldpan.Children[1];


                if (TvAzure.Tag.ToString().Trim().Equals(string.Empty))
                {
                    MessageBox.Show(ResManager.GetString("Error_Deleting_Azure_File" + cons.Language), string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                //Delete Directory
                string error = Azure.DeleteFolder(TvAzure.Tag.ToString().Trim(), Const.key());
                if (error.Length > 0)
                {
                    MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + error, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }


                //Delete at treeview
                int index = Tre_Azure.Items.IndexOf(Tre_Azure.SelectedItem);
                TreeViewItem parent = (Tre_Azure.SelectedItem as TreeViewItem).Parent as TreeViewItem;

                if (index < 0)
                {
                    index = parent.Items.IndexOf(Tre_Azure.SelectedItem);
                }

                if (index > -1)
                {
                    parent.Items.RemoveAt(index);
                }



            }
            catch (Exception ex)
            {
                MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
            }

        }




        /// <summary>
        /// 移動前、フォルダ名をチェックします
        /// </summary> 
        private string GetNewFolder(string newPath, string FolderName)
        {
            string NewFileName = newPath + FolderName;
            try
            {

                if (Directory.Exists(newPath + FolderName))
                {
                    int cont = 1;



                    while (Directory.Exists(NewFileName) == true)
                    {
                        NewFileName = newPath + FolderName + " (" + cont + ")";
                        cont++;
                    }


                }
            }
            catch (Exception ex)
            {
                return "1|" + ex.Message;
            }
            return "0|" + NewFileName;
        }


        /// <summary>
        /// With enter save edit Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeViewSaveLocal_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                TextBox textboxNewText = (TextBox)sender;


                StackPanel OldpanRename = (StackPanel)TvLocalBK.Header;
                StackPanel panRename = new StackPanel();
                TextBlock textRename = (TextBlock)OldpanRename.Children[1];

                if (!TvLocalBK.Tag.Equals(string.Empty) && !textboxNewText.Text.Equals(string.Empty))
                {
                    panRename.Orientation = Orientation.Horizontal;
                    Stream iconstm = this._MakeIconStream("CloseFolder.ico");
                    IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                    //IconBitmapDecoder icon = new IconBitmapDecoder(new Uri(System.IO.Path.Combine("Image/TreeView/", "CloseFolder.ico"), UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);                 

                    System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                    image.Height = Const.TreeIcoSize;
                    image.Source = icon.Frames[0];
                    panRename.Children.Add(image);
                }
                else
                {
                    return;
                }
                try
                {
                    string[] vecGetPath = TvLocalBK.Tag.ToString().Split('\\');
                    string GetPath = string.Empty;

                    if (vecGetPath.Length > 1)
                    {
                        for (int i = 0; i < vecGetPath.Length - 1; i++)
                        {
                            GetPath += vecGetPath[i] + "\\";
                        }
                    }
                    else
                    { GetPath = vecGetPath[0] + "\\"; }

                    GetPath += (GetPath.EndsWith(@"\") ? string.Empty : @"\") + textboxNewText.Text.Trim();

                    Directory.Move(TvLocalBK.Tag.ToString(), GetPath);

                    TextBlock textRenameTemp = new TextBlock();
                    textRenameTemp.Text = " " + textboxNewText.Text.Trim();
                    panRename.Children.Add(textRenameTemp);
                    //panRename.Children.Add(new TextBlock(new Run(" " + textboxNewText.Text)));
                    TvLocalBK.Header = panRename;

                    string oldPath=TvLocalBK.Tag.ToString();
                    TvLocalBK.Tag = GetPath;

                    foreach (TreeViewItem Temptree in TvLocalBK.Items)
                        Temptree.Tag = Temptree.Tag.ToString().Replace(oldPath, GetPath);

                    TvLocalBK = null;

                    BackgraoundLocal.Text = GetPath;
                    LocalGoTXT.Text = BackgraoundLocal.Text;                    
                    LocalGoTXT_KeyUp(sender, e);
                    LocalGoTXTButton();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ResManager.GetString("Error" + cons.Language) + ":" + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                }


            }
            else if (e.Key == System.Windows.Input.Key.Escape)
            {

                StackPanel OldpanRename = (StackPanel)TvLocalBK.Header;
                StackPanel panRename = new StackPanel();
                TextBlock textRename = (TextBlock)OldpanRename.Children[1];

                if (!TvLocalBK.Tag.Equals(string.Empty) && !textRename.Tag.Equals(string.Empty))
                {
                    panRename.Orientation = Orientation.Horizontal;
                    Stream iconstm = this._MakeIconStream("CloseFolder.ico");
                    IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                    //IconBitmapDecoder icon = new IconBitmapDecoder(new Uri(System.IO.Path.Combine("Image/TreeView/", "CloseFolder.ico"), UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);                                    
                    System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                    image.Height = Const.TreeIcoSize;
                    image.Source = icon.Frames[0];
                    panRename.Children.Add(image);
                }
                else
                {
                    return;
                }

                TextBlock textRenameTemp = new TextBlock();
                textRenameTemp.Text = " " + textRename.Tag.ToString().Trim();
                panRename.Children.Add(textRenameTemp);
                //panRename.Children.Add(new TextBlock(new Run(" " + textRename.Tag)));

                TvLocalBK.Header = panRename;
                TvLocalBK = null;
                return;

            }
        }


        /// <summary>
        /// With enter save edit Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeViewSaveAzure_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                TextBox textboxNewText = (TextBox)sender;


                StackPanel OldpanRename = (StackPanel)TvAzureBK.Header;
                StackPanel panRename = new StackPanel();
                TextBlock textRename = (TextBlock)OldpanRename.Children[1];

                if (!TvAzureBK.Tag.Equals(string.Empty) && !textboxNewText.Text.Equals(string.Empty))
                {
                    panRename.Orientation = Orientation.Horizontal;
                    Stream iconstm = this._MakeIconStream("CloseFolder.ico");
                    IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                    //IconBitmapDecoder icon = new IconBitmapDecoder(new Uri(System.IO.Path.Combine("Image/TreeView/", "CloseFolder.ico"), UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);                 
                    System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                    image.Height = Const.TreeIcoSize;
                    image.Source = icon.Frames[0];
                    panRename.Children.Add(image);
                }
                else
                {
                    return;
                }
                try
                {
                    string[] vecGetPath = TvAzureBK.Tag.ToString().Split('\\');
                    string GetPath = string.Empty;

                    if (vecGetPath.Length > 1)
                    {
                        for (int i = 0; i < vecGetPath.Length - 1; i++)
                        {
                            GetPath += vecGetPath[i] + "\\";
                        }
                    }
                    else
                    { GetPath = vecGetPath[0] + "\\"; }

                    GetPath += (GetPath.EndsWith(@"\") ? string.Empty : @"\") + textboxNewText.Text.Trim();

                    string error = Azure.MoveFolder(TvAzureBK.Tag.ToString(), GetPath, Const.key());
                    if (error.Length > 0)
                    {
                        MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + error, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    TextBlock textRenameTemp = new TextBlock();
                    textRenameTemp.Text = " " + textboxNewText.Text.Trim();
                    panRename.Children.Add(textRenameTemp);
                    //panRename.Children.Add(new TextBlock(new Run(" " + textboxNewText.Text)));
                    TvAzureBK.Header = panRename;

                    string oldPath = TvAzureBK.Tag.ToString();
                    TvAzureBK.Tag = GetPath;
                   
                    foreach (TreeViewItem Temptree in TvAzureBK.Items)
                        Temptree.Tag = Temptree.Tag.ToString().Replace(oldPath, GetPath);
                    
                    TvAzureBK = null;
                    
                    BackgraoundAzure.Text = GetPath;
                    AzureGoTXT.Text = BackgraoundAzure.Text;
                    AzureGoTXT_KeyUp(sender, e);
                    AzureGoTXTButton();

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language) + ": " + ex.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
                }

            }

            else if (e.Key == System.Windows.Input.Key.Escape)
            {

                StackPanel OldpanRename = (StackPanel)TvAzureBK.Header;
                StackPanel panRename = new StackPanel();
                TextBlock textRename = (TextBlock)OldpanRename.Children[1];

                if (!TvAzureBK.Tag.Equals(string.Empty) && !textRename.Tag.Equals(string.Empty))
                {
                    panRename.Orientation = Orientation.Horizontal;
                    Stream iconstm = this._MakeIconStream("CloseFolder.ico");
                    IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                    //IconBitmapDecoder icon = new IconBitmapDecoder(new Uri(System.IO.Path.Combine("Image/TreeView/", "CloseFolder.ico"), UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);                 
                    System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                    image.Height = Const.TreeIcoSize;
                    image.Source = icon.Frames[0];
                    panRename.Children.Add(image);
                }
                else
                {
                    return;
                }

                TextBlock textRenameTemp = new TextBlock();
                textRenameTemp.Text = " " + textRename.Tag.ToString().Trim();
                panRename.Children.Add(textRenameTemp);
                TvAzureBK.Header = panRename;
                TvAzureBK = null;
                return;

            }
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            Const cons = new Const();
            cons.Language = CBLanguage.SelectedIndex.ToString();
            Language_ChangeObject();
        }


        /// <summary>
        /// Language Changed object
        /// </summary>
        private void Language_ChangeObject()
        {
            ResManager = new System.Resources.ResourceManager("AzureDriverExplorer_Client.Properties.Resources", this.GetType().Assembly);


            Ri_Information.Header = ResManager.GetString("Information" + cons.Language).Trim();
            Ri_Information_Menu.Header = ResManager.GetString("Information" + cons.Language).Trim();
            this.Ri_Action.Header = ResManager.GetString("Ri_Action" + cons.Language).Trim();
            this.GrRefresh.Header = ResManager.GetString("Refresh" + cons.Language).Trim();


            this.Ri_View.Header = ResManager.GetString("Ri_View" + cons.Language).Trim();
            this.GrUploadListr.Header = ResManager.GetString("GrUploadListr" + cons.Language).Trim();
            this.Ri_bt_UploadList.Label = ResManager.GetString("Ri_bt_UploadList" + cons.Language).Trim();
            this.Ri_bt_DownList.Label = ResManager.GetString("Ri_bt_DownList" + cons.Language).Trim();

            this.Ri_Language.Header = ResManager.GetString("Ri_Language" + cons.Language).Trim();
            this.GrLanguage.Header = ResManager.GetString("GrLanguage" + cons.Language).Trim();

            this.Ri_Settings.Header = ResManager.GetString("Ri_Settings" + cons.Language).Trim();
            this.AddConfig.Header = ResManager.GetString("AddConfig" + cons.Language).Trim();


            this.Ri_bt_AddConfig.Label = ResManager.GetString("Ri_bt_AddConfig" + cons.Language).Trim();
            this.Ri_bt_ConfigEdit.Label = ResManager.GetString("Ri_bt_ConfigEdit" + cons.Language).Trim();
            this.Ri_bt_ConfigDelete.Label = ResManager.GetString("Ri_bt_ConfigDelete" + cons.Language).Trim();


            this.Ri_bt_AddVHD.Label = ResManager.GetString("Create" + cons.Language).Trim();
            this.Ri_bt_UploadVHD.Label = ResManager.GetString("Ri_bt_UploadVHD" + cons.Language).Trim();
            this.Ri_bt_BackUpVHD.Label = ResManager.GetString("Ri_bt_BackUpVHD" + cons.Language).Trim();
            this.Ri_bt_DeleteVHD.Label = ResManager.GetString("Ri_bt_DeleteVHD" + cons.Language).Trim();

            ColName.Content = ResManager.GetString("ColName" + cons.Language).Trim();
            ColDate.Content = ResManager.GetString("ColDate" + cons.Language).Trim();
            ColType.Content = ResManager.GetString("ColType" + cons.Language).Trim();
            ColSize.Content = ResManager.GetString("ColSize" + cons.Language).Trim();

            ColNameAzure.Content = ResManager.GetString("ColName" + cons.Language).Trim();
            ColDateAzure.Content = ResManager.GetString("ColDate" + cons.Language).Trim();
            ColTypeAzure.Content = ResManager.GetString("ColType" + cons.Language).Trim();
            ColSizeAzure.Content = ResManager.GetString("ColSize" + cons.Language).Trim();

            ColDProgressName.Header = ResManager.GetString("ColName" + cons.Language).Trim();
            ColDProgressProgress.Header = ResManager.GetString("ColProgressProgress" + cons.Language).Trim();
            ColDProgressOut.Header = ResManager.GetString("ColProgressOut" + cons.Language).Trim();
            ColDProgressIn.Header = ResManager.GetString("ColProgressIn" + cons.Language).Trim();

            ColUProgressName.Header = ResManager.GetString("ColName" + cons.Language).Trim();
            ColUProgressProgress.Header = ResManager.GetString("ColProgressProgress" + cons.Language).Trim();
            ColUProgressOut.Header = ResManager.GetString("ColProgressOut" + cons.Language).Trim();
            ColUProgressIn.Header = ResManager.GetString("ColProgressIn" + cons.Language).Trim();
        }


        /// <summary>
        /// TreeView Menu Language
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContextMenu_Opened(object sender, RoutedEventArgs e)
        {
            ResManager = new System.Resources.ResourceManager("AzureDriverExplorer_Client.Properties.Resources", this.GetType().Assembly);


            ContextMenu Menu = (ContextMenu)sender;
            MenuItem item1 = (MenuItem)Menu.Items[0];
            MenuItem item2 = (MenuItem)Menu.Items[2];
            MenuItem item3 = (MenuItem)Menu.Items[3];
            MenuItem item4 = (MenuItem)Menu.Items[4];

            item1.Header = ResManager.GetString("ViewUpdate_Update" + cons.Language).Trim();
            item2.Header = ResManager.GetString("NewFolder" + cons.Language).Trim();
            item3.Header = ResManager.GetString("RenameFolder" + cons.Language).Trim();
            item4.Header = ResManager.GetString("DeleteFolder" + cons.Language).Trim();
        }



        /// <summary>
        /// TreeView Menu Local Language
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListViewLocalMenu_Opened(object sender, RoutedEventArgs e)
        {
            ResManager = new System.Resources.ResourceManager("AzureDriverExplorer_Client.Properties.Resources", this.GetType().Assembly);


            ContextMenu Menu = (ContextMenu)sender;
            MenuItem item1 = (MenuItem)Menu.Items[0];
            MenuItem item2 = (MenuItem)Menu.Items[2];
            MenuItem item3 = (MenuItem)Menu.Items[3];
            MenuItem item4 = (MenuItem)Menu.Items[4];
            MenuItem item5 = (MenuItem)Menu.Items[6];
            item1.Header = ResManager.GetString("ViewUpdate_Update" + cons.Language).Trim();
            item2.Header = ResManager.GetString("ViewUpdate_Rename" + cons.Language).Trim();
            item3.Header = ResManager.GetString("ViewUpdate_Copy" + cons.Language).Trim();
            item4.Header = ResManager.GetString("ViewUpdate_Paste" + cons.Language).Trim();
            item5.Header = ResManager.GetString("ViewUpdate_Delete" + cons.Language).Trim();
        }



        /// <summary>
        /// TreeView Menu Azure Language
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListViewAzureMenu_Opened(object sender, RoutedEventArgs e)
        {
            ResManager = new System.Resources.ResourceManager("AzureDriverExplorer_Client.Properties.Resources", this.GetType().Assembly);


            ContextMenu Menu = (ContextMenu)sender;
            MenuItem item1 = (MenuItem)Menu.Items[0];
            MenuItem item2 = (MenuItem)Menu.Items[2];
            MenuItem item3 = (MenuItem)Menu.Items[3];
            MenuItem item4 = (MenuItem)Menu.Items[4];
            MenuItem item5 = (MenuItem)Menu.Items[6];
            item1.Header = ResManager.GetString("ViewDownload_Download" + cons.Language).Trim();
            item2.Header = ResManager.GetString("ViewDownload_Rename" + cons.Language).Trim();
            item3.Header = ResManager.GetString("ViewDownload_Copy" + cons.Language).Trim();
            item4.Header = ResManager.GetString("ViewDownload_Paste" + cons.Language).Trim();
            item5.Header = ResManager.GetString("ViewDownload_Delete" + cons.Language).Trim();
        }

        /// <summary>
        /// About画面を開く
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ri_Information_Click(object sender, RoutedEventArgs e)
        {
            popup.Visibility = Visibility.Visible;
            About about = new About();
            if (about.ShowDialog() == false)
            {
                popup.Visibility = Visibility.Collapsed;
            }
        }

        /// <summary>
        /// About画面を開く
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ri_InformationCodePlex_Click(object sender, RoutedEventArgs e)
        {
            var runExplorer = new System.Diagnostics.ProcessStartInfo();
            runExplorer.FileName = "explorer.exe";
            runExplorer.Arguments = @"http://azuredriveexplorer.codeplex.com/documentation";
            System.Diagnostics.Process.Start(runExplorer);
        }

        /// <summary>
        /// About画面を開く
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ri_InformationRakudou_Click(object sender, RoutedEventArgs e)
        {

            var runExplorer = new System.Diagnostics.ProcessStartInfo();
            runExplorer.FileName = "explorer.exe";
            runExplorer.Arguments = @"http://www.rakudou.co.jp/index.html";
            System.Diagnostics.Process.Start(runExplorer);

        }

        /// <summary>
        /// Open file used windows
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenFileLocal(object sender, MouseButtonEventArgs e)
        {
            DataList Item = (DataList)ListViewLocal.SelectedItem;

            if (Item != null)
            {
                //File
                if (!Item.HiddenBytes.Equals("Hidden"))
                {
                    var runExplorer = new System.Diagnostics.ProcessStartInfo();
                    runExplorer.FileName = "explorer.exe";
                    runExplorer.Arguments = Localpath + (Localpath.EndsWith(@"\") ? Item.Name : @"\" + Item.Name);
                    System.Diagnostics.Process.Start(runExplorer);
                }
                //Folder
                else
                {
                    try
                    {
                        Localpath = Localpath + (Localpath.EndsWith(@"\") ? Item.Name : @"\" + Item.Name);
                        LocalGoTXT.Text = Localpath;
                        string[] vecPath = LocalGoTXT.Text.Split('\\');
                        Expanded(Tre_Local, vecPath, ref Localpath);
                        LocalGoTXT.Text = Localpath;

                    }
                    catch (Exception ex)
                    { MessageBox.Show(ResManager.GetString("Error" + cons.Language).Trim() + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Information); }
                }
            }

        }



        /// <summary>
        /// Open Folder with list Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenFileAzure(object sender, MouseButtonEventArgs e)
        {
            DataList Item = (DataList)ListViewAzure.SelectedItem;

            if (Item != null)
            {
                //Folder
                if (Item.HiddenBytes.Equals("Hidden"))
                {

                    try
                    {
                        Azurepath = Azurepath + (Azurepath.EndsWith(@"\") ? Item.Name : @"\" + Item.Name);
                        AzureGoTXT.Text = Azurepath;
                        string[] vecPath = AzureGoTXT.Text.Split('\\');
                        Expanded(Tre_Azure, vecPath, ref Azurepath);
                        AzureGoTXT.Text = Azurepath;
                    }
                    catch (Exception ex)
                    { MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language).Trim() + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Information); }
                }
            }

        }


        /// <summary>
        /// Expanded treeview with toolbar direction Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocalGoTXT_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                LocalGoTXT.Text = LocalGoTXT.Text.Trim();
                LocalGoTXT.Text = LocalGoTXT.Text.Replace("/", @"\");
                try
                {
                    //if (Directory.Exists(LocalGoTXT.Text))
                    //{
                    string[] vecPath = LocalGoTXT.Text.Split('\\');
                    Expanded(Tre_Local, vecPath, ref Localpath);
                    LocalGoTXT.Text = Localpath;
                    LocalGoTXTButton();
                    // ListViewLocal.ItemsSource = GetLocalInformationFile(Localpath);

                    // }
                    //else
                    //    MessageBox.Show(ResManager.GetString("Error" + cons.Language).Trim() + ": " + ResManager.GetString("Error_LocalPath" + cons.Language).Trim(), string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                { MessageBox.Show(ResManager.GetString("Error" + cons.Language).Trim() + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Information); }
            }
            else if (e.Key == System.Windows.Input.Key.Escape)
            {
                LocalGoTXT.Text = Localpath;
                LocalGoTXTButton();
            }
        }


        /// <summary>
        /// Expanded treeview with toolbar direction Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AzureGoTXT_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                AzureGoTXT.Text = AzureGoTXT.Text.Trim();
                AzureGoTXT.Text = AzureGoTXT.Text.Replace("/", @"\");
                try
                {
                    //if (Directory.Exists(AzureGoTXT.Text))
                    //{
                    string[] vecPath = AzureGoTXT.Text.Split('\\');
                    Expanded(Tre_Azure, vecPath, ref Azurepath);
                    AzureGoTXT.Text = Azurepath;
                    ListViewAzure.ItemsSource = GetAzureInformationFile(Azurepath);

                    //}
                    //else
                    //    MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language).Trim() + ": " + ResManager.GetString("Error_LocalPath" + cons.Language).Trim(), string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                { MessageBox.Show(ResManager.GetString("Error_AzureError" + cons.Language).Trim() + ": " + ex, string.Empty, MessageBoxButton.OK, MessageBoxImage.Information); }
            }
            else if (e.Key == System.Windows.Input.Key.Escape)
            {
                AzureGoTXT.Text = Azurepath;
            }
        }


        /// <summary>
        /// Begine Search
        /// </summary>
        /// <param name="treeview"></param>
        /// <param name="vecPath"></param>
        protected void Expanded(TreeView treeview, string[] vecPath, ref string Originalpath)
        {
            bool existPath = false;
            for (int i = 0; i < vecPath.Length; i++)
            {
                if (!vecPath[i].Trim().Equals(string.Empty))
                {
                    existPath = false;
                    foreach (TreeViewItem items in treeview.Items)
                    {
                        StackPanel Oldpanpanel = (StackPanel)items.Header;
                        TextBlock textblock = (TextBlock)Oldpanpanel.Children[1];
                        string Temppath = vecPath[i].Trim().ToUpper();
                        if (textblock.Text.EndsWith(@"\"))
                            Temppath += @"\";
                        if (textblock.Text.Trim().ToUpper().Equals(Temppath))
                        {
                            Originalpath = Temppath;
                            items.IsSelected = true;
                            items.IsExpanded = true;
                            vecPath[i] = string.Empty;
                            Expanded(items, ref vecPath, ref Originalpath);
                            existPath = true;
                        }
                    }
                    if (!existPath)
                    {
                        MessageBox.Show(ResManager.GetString("Error" + cons.Language).Trim() + ": " + ResManager.GetString("Error_LocalPath" + cons.Language).Trim() + "[" + Originalpath + " >> " + vecPath[i] + "]", string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                        for (int j = 0; j < vecPath.Length; j++)
                            vecPath[j] = string.Empty;
                        break;
                    }
                }
            }
        }

        /// <summary>
        /// Search Items
        /// </summary>
        /// <param name="TreeViewitems"></param>
        /// <param name="vecPath"></param>
        protected void Expanded(TreeViewItem TreeViewitems, ref string[] vecPath, ref string Originalpath)
        {
            bool existPath = false;
            for (int i = 0; i < vecPath.Length; i++)
            {
                if (!vecPath[i].Trim().Equals(string.Empty))
                {
                    existPath = false;
                    foreach (TreeViewItem items in TreeViewitems.Items)
                    {
                        StackPanel Oldpanpanel = (StackPanel)items.Header;
                        TextBlock textblock = (TextBlock)Oldpanpanel.Children[1];
                        string Temppath = vecPath[i].Trim();
                        if (textblock.Text.EndsWith(@"\"))
                            Temppath += @"\";
                        if (textblock.Text.Trim().ToUpper().Equals(Temppath.ToUpper()))
                        {
                            Originalpath += Originalpath.EndsWith("\\") ? Temppath : @"\" + Temppath;
                            items.IsSelected = true;
                            items.IsExpanded = true;
                            vecPath[i] = string.Empty;
                            Expanded(items, ref vecPath, ref Originalpath);
                            existPath = true;
                        }
                    }
                    if (!existPath)
                    {
                        MessageBox.Show(ResManager.GetString("Error" + cons.Language).Trim() + ": " + ResManager.GetString("Error_LocalPath" + cons.Language).Trim() + "[" + Originalpath + " >> " + vecPath[i] + "]", string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                        for (int j = 0; j < vecPath.Length; j++)
                            vecPath[j] = string.Empty;

                        break;
                    }
                }
            }
        }

        /// <summary>
        /// Begine Search
        /// </summary>
        /// <param name="treeview"></param>
        /// <param name="vecPath"></param>
        protected void CreateItemViewSelected(TreeView treeview, string[] vecPath, ref string Originalpath)
        {
            bool existPath = false;
            for (int i = 0; i < vecPath.Length; i++)
            {
                if (!vecPath[i].Trim().Equals(string.Empty))
                {
                    existPath = false;
                    foreach (TreeViewItem items in treeview.Items)
                    {
                        StackPanel Oldpanpanel = (StackPanel)items.Header;
                        TextBlock textblock = (TextBlock)Oldpanpanel.Children[1];
                        string Temppath = vecPath[i].Trim().ToUpper();
                        if (textblock.Text.EndsWith(@"\"))
                            Temppath += @"\";
                        if (textblock.Text.Trim().ToUpper().Equals(Temppath))
                        {
                            Originalpath = Temppath;
                            vecPath[i] = string.Empty;
                            CreateItemViewSelected(items, ref vecPath, ref Originalpath);
                            existPath = true;
                        }
                    }
                    if (!existPath)
                    {
                        // MessageBox.Show(ResManager.GetString("Error" + cons.Language).Trim() + ": " + ResManager.GetString("Error_LocalPath" + cons.Language).Trim() + "[" + Originalpath + " >> " + vecPath[i] + "]", string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                        for (int j = 0; j < vecPath.Length; j++)
                            vecPath[j] = string.Empty;
                        break;
                    }
                }
            }
        }




        /// <summary>
        /// Search Items
        /// </summary>
        /// <param name="TreeViewitems"></param>
        /// <param name="vecPath"></param>
        protected void CreateItemViewSelected(TreeViewItem TreeViewitems, ref string[] vecPath, ref string Originalpath)
        {
            bool existPath = false;
            for (int i = 0; i < vecPath.Length; i++)
            {
                if (!vecPath[i].Trim().Equals(string.Empty))
                {
                    existPath = false;
                    foreach (TreeViewItem items in TreeViewitems.Items)
                    {
                        StackPanel Oldpanpanel = (StackPanel)items.Header;
                        TextBlock textblock = (TextBlock)Oldpanpanel.Children[1];
                        string Temppath = vecPath[i].Trim();
                        if (textblock.Text.EndsWith(@"\"))
                            Temppath += @"\";
                        if (textblock.Text.Trim().ToUpper().Equals(Temppath.ToUpper()))
                        {
                            Originalpath += Originalpath.EndsWith("\\") ? Temppath : @"\" + Temppath;
                            vecPath[i] = string.Empty;
                            CreateItemViewSelected(items, ref vecPath, ref Originalpath);
                            existPath = true;
                        }
                    }
                    if (!existPath)
                    {

                        TreeViewItem ItemChir = null;
                        //if (TreeViewitems.Items.Count == 0)
                        //{
                        //if ((i + 1) < vecPath.Length)
                        //{
                        Originalpath += Originalpath.EndsWith("\\") ? vecPath[i] : @"\" + vecPath[i];
                        ItemChir = CreateTreeViewItem(Originalpath, vecPath[i], "Image/TreeView/", "CloseFolder.ico");
                        ItemChir.Expanded += new RoutedEventHandler(treeViewAzure_Expand);
                        TreeViewitems.Items.Add(ItemChir);
                        TreeViewitems.Items.Refresh();
                        //}
                        //}
                        // else
                        //   ItemChir = CreateTreeViewItem(Originalpath, vecPath[i], "Image/TreeView/", "CloseFolder.ico");



                        //for (int j = 0; j < vecPath.Length; j++)
                        //    vecPath[j] = string.Empty;

                        // break;
                        vecPath[i] = string.Empty;
                    }
                }
            }
        }







        /// <summary>
        /// Begine Search for rename items
        /// </summary>
        /// <param name="treeview"></param>
        /// <param name="vecPath"></param>
        protected void ChangeNameItemView(TreeView treeview, ref string[] vecPath, string Originalpath, string OldName, string NewName)
        {
            bool existPath = false;
            for (int i = 0; i < vecPath.Length; i++)
            {
                if (!vecPath[i].Trim().Equals(string.Empty))
                {
                    existPath = false;
                    foreach (TreeViewItem items in treeview.Items)
                    {
                        StackPanel Oldpanpanel = (StackPanel)items.Header;
                        TextBlock textblock = (TextBlock)Oldpanpanel.Children[1];
                        string Temppath = vecPath[i].Trim().ToUpper();
                        if (textblock.Text.EndsWith(@"\"))
                            Temppath += @"\";
                        if (textblock.Text.Trim().ToUpper().Equals(Temppath))
                        {

                            vecPath[i] = string.Empty;
                            ChangeNameItemView(items, ref vecPath, Originalpath, OldName, NewName);
                            existPath = true;
                        }
                    }
                    if (!existPath)
                    {
                        // MessageBox.Show(ResManager.GetString("Error" + cons.Language).Trim() + ": " + ResManager.GetString("Error_LocalPath" + cons.Language).Trim() + "[" + Originalpath + " >> " + vecPath[i] + "]", string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                        for (int j = 0; j < vecPath.Length; j++)
                            vecPath[j] = string.Empty;
                        break;
                    }
                }
            }
        }


        /// <summary>
        /// Begine Search for rename items
        /// </summary>
        /// <param name="TreeViewitems"></param>
        /// <param name="vecPath"></param>
        protected void ChangeNameItemView(TreeViewItem TreeViewitems, ref string[] vecPath, string Originalpath, string OldName, string NewName)
        {
            bool existPath = false;
            for (int i = 0; i < vecPath.Length; i++)
            {
                if (!vecPath[i].Trim().Equals(string.Empty))
                {
                    existPath = false;
                    foreach (TreeViewItem items in TreeViewitems.Items)
                    {
                        StackPanel Oldpanpanel = (StackPanel)items.Header;
                        TextBlock textblock = (TextBlock)Oldpanpanel.Children[1];
                        string Temppath = vecPath[i].Trim();
                        if (textblock.Text.EndsWith(@"\"))
                            Temppath += @"\";
                        if (textblock.Text.Trim().ToUpper().Equals(Temppath.ToUpper()))
                        {

                            vecPath[i] = string.Empty;
                            if (!OldName.Equals(textblock.Text.Trim()))
                                ChangeNameItemView(items, ref vecPath, Originalpath, OldName, NewName);
                            else
                            {
                                StackPanel panRename = new StackPanel();

                                panRename.Orientation = Orientation.Horizontal;
                                Stream iconstm = this._MakeIconStream("CloseFolder.ico");
                                IconBitmapDecoder icon = new IconBitmapDecoder(iconstm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                                //IconBitmapDecoder icon = new IconBitmapDecoder(new Uri(System.IO.Path.Combine("Image/TreeView/", "CloseFolder.ico"), UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);                 
                                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                                image.Height = Const.TreeIcoSize;
                                image.Source = icon.Frames[0];
                                panRename.Children.Add(image);

                                TextBlock textRenameTemp = new TextBlock();
                                textRenameTemp.Text = " " + NewName.Trim();
                                panRename.Children.Add(textRenameTemp);
                                //panRename.Children.Add(new TextBlock(new Run(" " + textboxNewText.Text)));
                                items.Header = panRename;
                                items.Tag = Originalpath;


                            }
                            existPath = true;
                        }
                    }
                    if (!existPath)
                    {
                        vecPath[i] = string.Empty;
                    }
                }
            }
        }

        /// <summary>
        /// Main to enterKey Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocalGoTXT_KeyUp2(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                LocalGoTXT.Text = BackgraoundLocal.Text;
                LocalGoTXT_KeyUp(sender, e);
                LocalGoTXTButton();
                ListViewLocal.Focus();
            }
            else if (e.Key == System.Windows.Input.Key.Escape)
            {                
                LocalGoTXT_KeyUp(sender, e);
                LocalGoTXTButton();
                ListViewLocal.Focus();
            }
        }

        /// <summary>
        /// path Mask actived in chenged text
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocalGoTXT_TextChanged(object sender, TextChangedEventArgs e)
        {
            LocalGoTXTButton();
        }

        /// <summary>
        /// get path and set in the buttons Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        
        private void LocalGoTXTButton()
        {
        
                string[] vecPath = LocalGoTXT.Text.Split('\\');

                int count = 0;


                

                pathLocalMenu0.Items.Clear();
                pathLocalMenu1.Items.Clear();
                pathLocalMenu2.Items.Clear();
                pathLocalMenu3.Items.Clear();
                pathLocalMenu0.Visibility = Visibility.Hidden;
                pathLocalMenu1.Visibility = Visibility.Hidden;
                pathLocalMenu2.Visibility = Visibility.Hidden;
                pathLocalMenu3.Visibility = Visibility.Hidden;

                pathLocal0.Visibility = Visibility.Hidden;
                pathLocal1.Visibility = Visibility.Hidden;
                pathLocal2.Visibility = Visibility.Hidden;
                pathLocal3.Visibility = Visibility.Hidden;

                for (int i = vecPath.Length - 1; i > -1; i--)
                {
                    if (!vecPath[i].Equals(string.Empty))
                    {
                        switch (count)
                        {
                            case 0: TextBlockReturnButton(pathLocal0, LocalGoTXT.Text.Trim(), i, vecPath[i]);
                                pathLocal0.Visibility = Visibility.Visible;

                                ////////////////////////////
                                pathLocalMenu0.Visibility = Visibility.Visible;
                                CompleteComboBox(pathLocalMenu0, LocalGoTXT.Text.Trim(), i);
                                break;
                            case 1: copybutton(pathLocal1, pathLocal0);

                                TextBlockReturnButton(pathLocal0, LocalGoTXT.Text.Trim(), i, vecPath[i]);
                                pathLocal1.Visibility = Visibility.Visible;

                                ////////////////////////////
                                pathLocalMenu1.Visibility = Visibility.Visible;
                                CompleteComboBox(pathLocalMenu1, LocalGoTXT.Text.Trim(), i);
                                copyCombobox(pathLocalMenu0, pathLocalMenu1);
                                break;
                            case 2: copybutton(pathLocal2, pathLocal1);
                                copybutton(pathLocal1, pathLocal0);
                                TextBlockReturnButton(pathLocal0, LocalGoTXT.Text.Trim(), i, vecPath[i]);
                                pathLocal2.Visibility = Visibility.Visible;

                                ////////////////////////////
                                pathLocalMenu2.Visibility = Visibility.Visible;
                                CompleteComboBox(pathLocalMenu2, LocalGoTXT.Text.Trim(), i);
                                copyCombobox(pathLocalMenu1, pathLocalMenu2);
                                copyCombobox(pathLocalMenu0, pathLocalMenu1);
                                break;
                            case 3: copybutton(pathLocal3, pathLocal2);
                                copybutton(pathLocal2, pathLocal1);
                                copybutton(pathLocal1, pathLocal0);
                                TextBlockReturnButton(pathLocal0, LocalGoTXT.Text.Trim(), i, vecPath[i]);
                                pathLocal3.Visibility = Visibility.Visible;

                                ////////////////////////////
                                pathLocalMenu3.Visibility = Visibility.Visible;
                                CompleteComboBox(pathLocalMenu3, LocalGoTXT.Text.Trim(), i);
                                copyCombobox(pathLocalMenu2, pathLocalMenu3);
                                copyCombobox(pathLocalMenu1, pathLocalMenu2);
                                copyCombobox(pathLocalMenu0, pathLocalMenu1);
                                break;
                        }
                        count++;
                        LocalGoTXT.Visibility = Visibility.Hidden;
                    }

                }
            }

            
      
        /// <summary>
        /// Copy parametor button1 to button2
        /// </summary>
        /// <param name="com1"></param>
        /// <param name="com2"></param>
        protected void copyCombobox(ComboBox com1, ComboBox com2)
        {
            ComboBox temp = new ComboBox();
            foreach (TextBlock item in com1.Items)
            {
                TextBlock tbTemp = new TextBlock();
                tbTemp.Text = item.Text;
                tbTemp.Tag = item.Tag;
                temp.Items.Add(tbTemp);
            }

            com1.Items.Clear();
            if (com2.Items.Count > 0)
                foreach (TextBlock item in com2.Items)
                {
                    TextBlock tbTemp = new TextBlock();
                    tbTemp.Text = item.Text;
                    tbTemp.Tag = item.Tag;
                    com1.Items.Add(tbTemp);
                }

            com2.Items.Clear();
            if (temp.Items.Count > 0)
                foreach (TextBlock item in temp.Items)
                {
                    TextBlock tbTemp = new TextBlock();
                    tbTemp.Text = item.Text;
                    tbTemp.Tag = item.Tag;
                    com2.Items.Add(tbTemp);
                }


        }


        /// <summary>
        /// ComboBox
        /// </summary>
        /// <param name="com"></param>
        /// <param name="path"></param>
        /// <param name="stop"></param>
        protected void CompleteComboBox(ComboBox com, string path, int stop)
        {
            string[] vecpath = path.Split('\\');
            string organize = string.Empty;
            for (int i = 0; i <= stop; i++)
                organize += vecpath[i] + @"\";

            try
            {
                string[] directory = Directory.GetDirectories(organize);

                foreach (string folder in directory)
                {
                    TextBlock item = new TextBlock();
                    item.Tag = organize;
                    string Temppath = System.IO.Path.GetFileName(folder);
                    if (Temppath.Equals(string.Empty))
                        item.Text = folder;
                    else
                        item.Text = Temppath;

                    com.Items.Add(item);

                }
                if (directory.Length == 0)
                {
                    TextBlock item = new TextBlock();
                    item.Tag = organize;
                    string Temppath = System.IO.Path.GetDirectoryName(organize);
                    Temppath = System.IO.Path.GetFileName(Temppath);
                    if (Temppath.Equals(string.Empty))
                        item.Text = organize + "<";
                    else
                        item.Text = Temppath + "<";

                    com.Items.Add(item);
                }

                BackgraoundLocal.Text = "";
            }
            catch { }
        }

        /// <summary>
        /// copy propety of button
        /// </summary>
        /// <param name="but1"></param>
        /// <param name="but2"></param>
        protected void copybutton(Button but1, Button but2)
        {
            TextBlock text = new TextBlock();
            text = (TextBlock)but2.Content;

            but1.Content = (new TextBlock { Text = text.Text });
            but1.Tag = but2.Tag;

        }

        protected void TextBlockReturnButton(Button but, string path, int stop, string stoppath)
        {

            string[] vecpath = path.Split('\\');
            string organize = string.Empty;
            for (int i = 0; i <= stop; i++)
                organize += vecpath[i] + @"\";

            TextBlock text = new TextBlock();
            text.Text = stoppath;
            but.Content = text;
            but.Tag = organize;


        }

        /// <summary>
        /// visible path buttons Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocalGoTXT_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            //LocalGoTXT.Visibility = Visibility.Visible;
            //LocalGoTXT.Focus();
            //BackgraoundLocal.Visibility = Visibility.Collapsed;
            BackgraoundLocal.Text = LocalGoTXT.Text;
            pathLocalMenu0.Visibility = Visibility.Hidden;
            pathLocalMenu1.Visibility = Visibility.Hidden;
            pathLocalMenu2.Visibility = Visibility.Hidden;
            pathLocalMenu3.Visibility = Visibility.Hidden;
            pathLocal0.Visibility = Visibility.Hidden;
            pathLocal1.Visibility = Visibility.Hidden;
            pathLocal2.Visibility = Visibility.Hidden;
            pathLocal3.Visibility = Visibility.Hidden;
        }

        /// <summary>
        /// get path button Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pathLocal0_Click(object sender, RoutedEventArgs e)
        {
            Button but = (Button)sender;
            string[] vecPath = but.Tag.ToString().Split('\\');
            Expanded(Tre_Local, vecPath, ref Localpath);
            LocalGoTXT.Text = Localpath;
        }


        /// <summary>
        /// Path select combobox Local
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pathLocalMenu0_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox com = (ComboBox)sender;
            if (com.SelectedIndex > -1)
            {

                TextBlock textblock = (TextBlock)com.Items[com.SelectedIndex];
                if (textblock.Text.EndsWith("<"))
                    return;
                string path = textblock.Tag.ToString() + (textblock.Tag.ToString().EndsWith(@"\") ? string.Empty : @"\") + textblock.Text;
                string[] vecPath = path.Split('\\');
                Expanded(Tre_Local, vecPath, ref Localpath);
                LocalGoTXT.Text = Localpath;
                //com.Items.Clear();
            }
        }



        /// <summary>
        /// get path and set in the buttons Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
       
        private void AzureGoTXTButton()
        {

            string[] vecPath = AzureGoTXT.Text.Split('\\');

            int count = 0;

            pathAzureMenu0.Items.Clear();
            pathAzureMenu1.Items.Clear();
            pathAzureMenu2.Items.Clear();
            pathAzureMenu3.Items.Clear();
            pathAzureMenu0.Visibility = Visibility.Hidden;
            pathAzureMenu1.Visibility = Visibility.Hidden;
            pathAzureMenu2.Visibility = Visibility.Hidden;
            pathAzureMenu3.Visibility = Visibility.Hidden;

            pathAzure0.Visibility = Visibility.Hidden;
            pathAzure1.Visibility = Visibility.Hidden;
            pathAzure2.Visibility = Visibility.Hidden;
            pathAzure3.Visibility = Visibility.Hidden;

            for (int i = vecPath.Length - 1; i > -1; i--)
            {
                if (!vecPath[i].Equals(string.Empty))
                {
                    switch (count)
                    {
                        case 0: TextBlockReturnButton(pathAzure0, AzureGoTXT.Text.Trim(), i, vecPath[i]);
                            pathAzure0.Visibility = Visibility.Visible;

                            ////////////////////////////
                            pathAzureMenu0.Visibility = Visibility.Visible;
                            CompleteComboBoxAzure(pathAzureMenu0, AzureGoTXT.Text.Trim(), i);
                            break;
                        case 1: copybutton(pathAzure1, pathAzure0);

                            TextBlockReturnButton(pathAzure0, AzureGoTXT.Text.Trim(), i, vecPath[i]);
                            pathAzure1.Visibility = Visibility.Visible;

                            ////////////////////////////
                            pathAzureMenu1.Visibility = Visibility.Visible;
                            CompleteComboBoxAzure(pathAzureMenu1, AzureGoTXT.Text.Trim(), i);
                            copyCombobox(pathAzureMenu0, pathAzureMenu1);
                            break;
                        case 2: copybutton(pathAzure2, pathAzure1);
                            copybutton(pathAzure1, pathAzure0);
                            TextBlockReturnButton(pathAzure0, AzureGoTXT.Text.Trim(), i, vecPath[i]);
                            pathAzure2.Visibility = Visibility.Visible;

                            ////////////////////////////
                            pathAzureMenu2.Visibility = Visibility.Visible;
                            CompleteComboBoxAzure(pathAzureMenu2, AzureGoTXT.Text.Trim(), i);
                            copyCombobox(pathAzureMenu1, pathAzureMenu2);
                            copyCombobox(pathAzureMenu0, pathAzureMenu1);
                            break;
                        case 3: copybutton(pathAzure3, pathAzure2);
                            copybutton(pathAzure2, pathAzure1);
                            copybutton(pathAzure1, pathAzure0);
                            TextBlockReturnButton(pathAzure0, AzureGoTXT.Text.Trim(), i, vecPath[i]);
                            pathAzure3.Visibility = Visibility.Visible;

                            ////////////////////////////
                            pathAzureMenu3.Visibility = Visibility.Visible;
                            CompleteComboBoxAzure(pathAzureMenu3, AzureGoTXT.Text.Trim(), i);
                            copyCombobox(pathAzureMenu2, pathAzureMenu3);
                            copyCombobox(pathAzureMenu1, pathAzureMenu2);
                            copyCombobox(pathAzureMenu0, pathAzureMenu1);
                            break;
                    }
                    count++;
                    AzureGoTXT.Visibility = Visibility.Hidden;
                }

            }



        }

        /// <summary>
        /// Main to enterKey Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AzureGoTXT_KeyUp2(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                AzureGoTXT.Text = BackgraoundAzure.Text;
                AzureGoTXT_KeyUp(sender, e);
                AzureGoTXTButton();
                ListViewAzure.Focus();
            }
            else if (e.Key == System.Windows.Input.Key.Escape)
            {
                AzureGoTXT_KeyUp(sender, e);
                AzureGoTXTButton();
                ListViewAzure.Focus();
            }
        }

        /// <summary>
        /// get path button Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pathAzure0_Click(object sender, RoutedEventArgs e)
        {
            Button but = (Button)sender;
            string[] vecPath = but.Tag.ToString().Split('\\');
            Expanded(Tre_Azure, vecPath, ref Azurepath);
            AzureGoTXT.Text = Azurepath;
        }

        /// <summary>
        /// visible path buttons Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AzureGoTXT_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            //AzureGoTXT.Visibility = Visibility.Visible;
            BackgraoundAzure.Text = AzureGoTXT.Text;
            pathAzureMenu0.Visibility = Visibility.Hidden;
            pathAzureMenu1.Visibility = Visibility.Hidden;
            pathAzureMenu2.Visibility = Visibility.Hidden;
            pathAzureMenu3.Visibility = Visibility.Hidden;
            pathAzure0.Visibility = Visibility.Hidden;
            pathAzure1.Visibility = Visibility.Hidden;
            pathAzure2.Visibility = Visibility.Hidden;
            pathAzure3.Visibility = Visibility.Hidden;
        }


        /// <summary>
        /// Path select combobox Azure
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pathAzureMenu0_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox com = (ComboBox)sender;
            if (com.SelectedIndex > -1)
            {

                TextBlock textblock = (TextBlock)com.Items[com.SelectedIndex];
                if (textblock.Text.EndsWith("<"))
                    return;
                string path = textblock.Tag.ToString() + (textblock.Tag.ToString().EndsWith(@"\") ? string.Empty : @"\") + textblock.Text;
                string[] vecPath = path.Split('\\');
                Expanded(Tre_Azure, vecPath, ref Azurepath);
                AzureGoTXT.Text = Azurepath;
                //com.Items.Clear();
            }
        }


        /// <summary>
        /// ComboBox Azure
        /// </summary>
        /// <param name="com"></param>
        /// <param name="path"></param>
        /// <param name="stop"></param>
        protected void CompleteComboBoxAzure(ComboBox com, string path, int stop)
        {
            string[] vecpath = path.Split('\\');
            string organize = string.Empty;
            for (int i = 0; i <= stop; i++)
                organize += vecpath[i] + @"\";

            try
            {
                GetListVHD.ArrayOfString directory = Azure.getDirectory(organize, Const.key());

                foreach (string folder in directory)
                {
                    TextBlock item = new TextBlock();
                    item.Tag = organize;
                    string Temppath = System.IO.Path.GetFileName(folder);
                    if (Temppath.Equals(string.Empty))
                        item.Text = folder;
                    else
                        item.Text = Temppath;

                    com.Items.Add(item);

                }
                if (directory.Count == 0)
                {
                    TextBlock item = new TextBlock();
                    item.Tag = organize;
                    string Temppath = System.IO.Path.GetDirectoryName(organize);
                    Temppath = System.IO.Path.GetFileName(Temppath);
                    if (Temppath.Equals(string.Empty))
                        item.Text = organize + "<";
                    else
                        item.Text = Temppath + "<";

                    com.Items.Add(item);
                }
                BackgraoundAzure.Text = "";
            }
            catch { }
        }

        /// <summary>
        /// path Mask actived in chenged text
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AzureGoTXT_TextChanged(object sender, TextChangedEventArgs e)
        {
            AzureGoTXTButton();
        }



    }


}

